Skip to content

Commit 5781237

Browse files
committed
Merge branch 'enh/state-through-store' of github.com:odeimaiz/osparc-simcore into enh/state-through-store
2 parents 46d5ff5 + 53434ef commit 5781237

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,73 @@ qx.Class.define("osparc.store.Store", {
429429
return null;
430430
},
431431

432+
getStudyState: function(studyId) {
433+
osparc.data.Resources.fetch("studies", "state", {
434+
url: {
435+
"studyId": studyId
436+
}
437+
})
438+
.then(({state}) => {
439+
this.setStudyState(studyId, state);
440+
});
441+
},
442+
443+
setStudyState: function(studyId, state) {
444+
const studiesWStateCache = this.getStudies();
445+
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
446+
if (idx !== -1) {
447+
studiesWStateCache[idx]["state"] = state;
448+
}
449+
450+
const currentStudy = this.getCurrentStudy();
451+
if (currentStudy && currentStudy.getUuid() === studyId) {
452+
currentStudy.setState(state);
453+
}
454+
455+
this.fireDataEvent("studyStateChanged", {
456+
studyId,
457+
state,
458+
});
459+
},
460+
461+
setStudyDebt: function(studyId, debt) {
462+
// init object if it does not exist
463+
if (this.__studiesInDebt === null) {
464+
this.__studiesInDebt = {};
465+
}
466+
if (debt) {
467+
this.__studiesInDebt[studyId] = debt;
468+
} else {
469+
delete this.__studiesInDebt[studyId];
470+
}
471+
472+
const studiesWStateCache = this.getStudies();
473+
const idx = studiesWStateCache.findIndex(studyWStateCache => studyWStateCache["uuid"] === studyId);
474+
if (idx !== -1) {
475+
if (debt) {
476+
studiesWStateCache[idx]["debt"] = debt;
477+
} else {
478+
delete studiesWStateCache[idx]["debt"];
479+
}
480+
}
481+
482+
this.fireDataEvent("studyDebtChanged", {
483+
studyId,
484+
debt,
485+
});
486+
},
487+
488+
getStudyDebt: function(studyId) {
489+
if (this.__studiesInDebt && studyId in this.__studiesInDebt) {
490+
return this.__studiesInDebt[studyId];
491+
}
492+
return null;
493+
},
494+
495+
isStudyInDebt: function(studyId) {
496+
return Boolean(this.getStudyDebt(studyId));
497+
},
498+
432499
reloadCreditPrice: function() {
433500
const store = osparc.store.Store.getInstance();
434501
store.setCreditPrice(null);

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,62 @@ qx.Class.define("osparc.store.Study", {
8585
return osparc.data.Resources.fetch("studies", "patch", params);
8686
},
8787

88+
getPage: function(params, options) {
89+
return osparc.data.Resources.fetch("studies", "getPage", params, options)
90+
},
91+
92+
getPageTrashed: function(params, options) {
93+
return osparc.data.Resources.fetch("studies", "getPageTrashed", params, options)
94+
},
95+
96+
getPageSearch: function(params, options) {
97+
return osparc.data.Resources.fetch("studies", "getPageSearch", params, options);
98+
},
99+
100+
getActive: function(clientSessionID) {
101+
const params = {
102+
url: {
103+
tabId: clientSessionID,
104+
}
105+
};
106+
return osparc.data.Resources.fetch("studies", "getActive", params)
107+
},
108+
109+
getOne: function(studyId) {
110+
const params = {
111+
url: {
112+
studyId
113+
}
114+
};
115+
return osparc.data.Resources.fetch("studies", "getOne", params)
116+
},
117+
118+
deleteStudy: function(studyId) {
119+
const params = {
120+
url: {
121+
studyId
122+
}
123+
};
124+
return osparc.data.Resources.fetch("studies", "delete", params)
125+
.then(() => {
126+
osparc.store.Store.getInstance().remove("studies", "uuid", studyId);
127+
})
128+
.catch(err => {
129+
console.error(err);
130+
throw err;
131+
});
132+
},
133+
134+
patchStudy: function(studyId, patchData) {
135+
const params = {
136+
url: {
137+
studyId,
138+
},
139+
data: patchData
140+
};
141+
return osparc.data.Resources.fetch("studies", "patch", params);
142+
},
143+
88144
patchStudyData: function(studyData, fieldKey, value) {
89145
if (osparc.data.model.Study.OwnPatch.includes(fieldKey)) {
90146
console.error(fieldKey, "has it's own PATCH path");
@@ -201,6 +257,22 @@ qx.Class.define("osparc.store.Study", {
201257
});
202258
},
203259

260+
untrashStudy: function(studyId) {
261+
const params = {
262+
url: {
263+
studyId
264+
}
265+
};
266+
return osparc.data.Resources.fetch("studies", "trash", params)
267+
.then(() => {
268+
osparc.store.Store.getInstance().remove("studies", "uuid", studyId);
269+
})
270+
.catch(err => {
271+
console.error(err);
272+
throw err;
273+
});
274+
},
275+
204276
untrashStudy: function(studyId) {
205277
const params = {
206278
url: {

0 commit comments

Comments
 (0)