Skip to content

Commit 76be64b

Browse files
committed
add and remove tag
1 parent d971ba2 commit 76be64b

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

services/static-webserver/client/source/class/osparc/form/tag/TagManager.js

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -155,43 +155,17 @@ qx.Class.define("osparc.form.tag.TagManager", {
155155
return tagButton;
156156
},
157157

158-
__getAddTagPromise: function(tagId) {
159-
const params = {
160-
url: {
161-
tagId,
162-
studyId: this.__resourceId
163-
}
164-
};
165-
return osparc.data.Resources.fetch("studies", "addTag", params);
166-
},
167-
168-
__getRemoveTagPromise: function(tagId) {
169-
const params = {
170-
url: {
171-
tagId,
172-
studyId: this.__resourceId
173-
}
174-
};
175-
return osparc.data.Resources.fetch("studies", "removeTag", params);
176-
},
177-
178158
__saveAddTag: function(tagId, tagButton) {
179-
this.__getAddTagPromise(tagId)
159+
osparc.store.Study.addTag(this.__resourceId, tagId)
180160
.then(() => this.__selectedTags.push(tagId))
181-
.catch(err => {
182-
console.error(err);
183-
tagButton.setValue(false);
184-
})
161+
.catch(() => tagButton.setValue(false))
185162
.finally(() => tagButton.setFetching(false));
186163
},
187164

188165
__saveRemoveTag: function(tagId, tagButton) {
189-
this.__getRemoveTagPromise(tagId)
166+
osparc.store.Study.removeTag(this.__resourceId, tagId)
190167
.then(() => this.__selectedTags.remove(tagId))
191-
.catch(err => {
192-
console.error(err);
193-
tagButton.setValue(true);
194-
})
168+
.catch(() => tagButton.setValue(true))
195169
.finally(() => tagButton.setFetching(false));
196170
},
197171

@@ -203,14 +177,14 @@ qx.Class.define("osparc.form.tag.TagManager", {
203177
for (let i=0; i<this.__selectedTags.length; i++) {
204178
const tagId = this.__selectedTags.getItem(i);
205179
if (!this.__studyData["tags"].includes(tagId)) {
206-
updatedStudy = await this.__getAddTagPromise(tagId)
180+
updatedStudy = await osparc.store.Study.addTag(this.__resourceId, tagId)
207181
.then(updatedData => updatedData);
208182
}
209183
}
210184
for (let i=0; i<this.__studyData["tags"].length; i++) {
211185
const tagId = this.__studyData["tags"][i];
212186
if (!this.__selectedTags.includes(tagId)) {
213-
updatedStudy = await this.__getRemoveTagPromise(tagId)
187+
updatedStudy = await osparc.store.Study.removeTag(this.__resourceId, tagId)
214188
.then(updatedData => updatedData);
215189
}
216190
}

services/static-webserver/client/source/class/osparc/store/Study.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ qx.Class.define("osparc.store.Study", {
160160
});
161161
},
162162

163+
addTag: function(studyId, tagId) {
164+
const params = {
165+
url: {
166+
tagId,
167+
studyId,
168+
}
169+
};
170+
return osparc.data.Resources.fetch("studies", "addTag", params)
171+
.catch(err => console.error(err));
172+
},
173+
174+
removeTag: function(studyId, tagId) {
175+
const params = {
176+
url: {
177+
tagId,
178+
studyId,
179+
}
180+
};
181+
return osparc.data.Resources.fetch("studies", "removeTag", params)
182+
.catch(err => console.error(err));
183+
},
184+
163185
addCollaborators: function(studyData, newCollaborators) {
164186
const promises = [];
165187
Object.keys(newCollaborators).forEach(gid => {

0 commit comments

Comments
 (0)