Skip to content

Commit

Permalink
Fix tutorial tags
Browse files Browse the repository at this point in the history
Co-authored-by: Iris Benoit-Martin <[email protected]>
Co-authored-by: Jérémie Jadé <[email protected]>
Co-authored-by: Laura Bergoens <[email protected]>
  • Loading branch information
4 people committed Sep 30, 2024
1 parent 06a01d0 commit c6358b7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
40 changes: 16 additions & 24 deletions pix-editor/app/components/form/tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,41 @@ export default class TutorialForm extends Component {
}

@action
selectTag(item) {
async selectTag(item) {
const tutorial = this.args.tutorial;
const tags = await tutorial.tags;
if (item.id === 'create') {
const value = document.querySelector('.tutorial-search .ember-power-select-search-input').value;
if (value.indexOf('[') !== -1) {
const pos = value.indexOf('[');
const length = value.length;
const title = value.slice(0, pos);
const notes = value.slice(pos + 1, length - 1);
this.store.createRecord('tag', {
const tag = await this.store.createRecord('tag', {
title: title,
notes: notes,
notes: notes,
pixId: this.idGenerator.newId('tag'),
}).save()
.then((tag) => {
tutorial.tags.pushObject(tag);
});
}).save();
tags.pushObject(tag);
} else {
this.store.createRecord('tag', {
const tag = await this.store.createRecord('tag', {
title: value,
}).save()
.then((tag) => {
tutorial.tags.pushObject(tag);
});
}).save();
tags.pushObject(tag);
}
} else {
return this.store.findRecord('tag', item.id)
.then((tag) => {
if (tutorial.tags.indexOf(tag) === -1) {
tutorial.tags.pushObject(tag);
}
});
const tag = await this.store.findRecord('tag', item.id);
if (tags.indexOf(tag) === -1) {
tags.pushObject(tag);
}
}
}

@action
unselectTag(id) {
async unselectTag(id) {
const tutorial = this.args.tutorial;
tutorial.tags.forEach((tag) => {
if (tag.id === id) {
tutorial.tags.removeObject(tag);
}
});
const tags = await tutorial.tags;
this.args.tutorial.tags = tags.filter((tag) => tag.id !== id);
}

@action
Expand Down
2 changes: 1 addition & 1 deletion pix-editor/app/models/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default class TagModel extends Model {

// Une relation surprenante ☝️🤓
@hasMany('skill', { async: true, inverse: null }) skills;
@hasMany('tutorial', { async: true, inverse: 'tag' }) tutorials;
@hasMany('tutorial', { async: true, inverse: 'tags' }) tutorials;
}

0 comments on commit c6358b7

Please sign in to comment.