Skip to content

Commit

Permalink
Separating (decoupling) edit and store and per each cam geneontology/…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmushayahama committed Jan 13, 2021
1 parent 018d648 commit 2e6f0a5
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 29 deletions.
7 changes: 0 additions & 7 deletions src/@noctua.form/services/cam.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,6 @@ export class CamService {
return self._noctuaGraphService.resetModel(cam);
}


bulkEdit(cam: Cam) {
const self = this;

return self._noctuaGraphService.bulkEditAnnoton(cam);
}

reviewChanges(cam: Cam, stats: CamStats) {
const terms = cam.reviewTermChanges(stats);

Expand Down
51 changes: 46 additions & 5 deletions src/@noctua.form/services/cams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,43 @@ export class CamsService {
replace(entities: Entity[], replaceWithTerm: Entity) {
const self = this;
const groupedEntities = groupBy(entities, 'modelId') as { string: Entity[] };
const cams: Cam[] = []

each(groupedEntities, (values: Entity[], key) => {
const cam: Cam = find(this.cams, { id: key });
cam.replace(entities, replaceWithTerm);
if (cam) {
cam.replace(entities, replaceWithTerm);
cams.push(cam)
}
});

self.reviewChanges();
return self.bulkEdit();
return self.bulkEdit(cams);
}

bulkEdit(store = false) {
bulkEdit(cams: Cam[]): Observable<any> {
const self = this;
const promises = [];

each(this.cams, (cam: Cam) => {
promises.push(self._noctuaGraphService.bulkEditAnnoton(cam, store));
each(cams, (cam: Cam) => {
promises.push(self._noctuaGraphService.bulkEditAnnoton(cam));
});

return forkJoin(promises);
}

storeModels(cams: Cam[]): Observable<any> {
const self = this;
const promises = [];

each(cams, (cam: Cam) => {
promises.push(self._noctuaGraphService.storeModel(cam));
});

return forkJoin(promises);
}


bulkStoredModel() {
const self = this;
const promises = [];
Expand Down Expand Up @@ -236,6 +252,31 @@ export class CamsService {
this.onCamsCheckoutChanged.next(result);
}


reviewCamChanges(cam: Cam) {
const self = this;
const details = [];
const stats = new CamStats();

const changes = self.camService.reviewChanges(cam, stats);
if (changes) {
details.push({
cam: cam,
changes: changes
});
}

stats.camsCount = details.length;
stats.updateTotal();

const result = {
stats: stats,
details: details
};

return result
}

clearCams() {
this.cams = [];
this.onCamsChanged.next(this.cams);
Expand Down
17 changes: 13 additions & 4 deletions src/@noctua.form/services/graph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,18 @@ export class NoctuaGraphService {
return cam.artManager.request_with(reqs);
}

storeModel(cam: Cam) {
const self = this;
const reqs = new minerva_requests.request_set(self.noctuaUserService.baristaToken, cam.id);

if (self.noctuaUserService.user && self.noctuaUserService.user.groups.length > 0) {
reqs.use_groups([self.noctuaUserService.user.group.id]);
}

reqs.store_model(cam.id);
return cam.manager.request_with(reqs);
}

storedModel(cam: Cam) {
const self = this;
const reqs = new minerva_requests.request_set(self.noctuaUserService.baristaToken, cam.id);
Expand Down Expand Up @@ -700,7 +712,7 @@ export class NoctuaGraphService {
}


bulkEditAnnoton(cam: Cam, store = false) {
bulkEditAnnoton(cam: Cam) {
const self = this;
const reqs = new minerva_requests.request_set(self.noctuaUserService.baristaToken, cam.id);
each(cam.annotons, (annoton: Annoton) => {
Expand All @@ -717,9 +729,6 @@ export class NoctuaGraphService {
reqs.use_groups([self.noctuaUserService.user.group.id]);
}

if (store) {
reqs.store_model(cam.id);
}
return cam.manager.request_with(reqs);
}

Expand Down
29 changes: 20 additions & 9 deletions src/@noctua.search/components/art-basket/art-basket.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
});
}

ngOnDestroy(): void {
this._unsubscribeAll.next();
this._unsubscribeAll.complete();
}

selectItem(artBasketItem: ArtBasketItem) {
this.camsService.onSelectedCamChanged.next(artBasketItem.id);
const q = '#noc-review-cams-' + artBasketItem.displayId;
Expand Down Expand Up @@ -159,17 +164,31 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
self.noctuaSearchMenuService.selectMiddlePanel(MiddlePanel.reviewChanges);
}


submitChanges() {
const self = this;

this.storeModels(self.camsService.cams)
}

submitChange(cam: Cam) {
this.storeModels([cam])
}

close() {
this.noctuaSearchMenuService.closeLeftDrawer();
}

private storeModels(cams: Cam[]) {
const self = this;
const success = (replace) => {
if (replace) {
const element = document.querySelector('#noc-review-results');

if (element) {
element.scrollTop = 0;
}
self.noctuaReviewSearchService.bulkEdit(true).pipe(takeUntil(this._unsubscribeAll))
self.camsService.storeModels(self.camsService.cams).pipe(takeUntil(this._unsubscribeAll))
.subscribe(cams => {
if (!cams) {
return;
Expand Down Expand Up @@ -202,12 +221,4 @@ export class ArtBasketComponent implements OnInit, OnDestroy {
}
}

close() {
this.noctuaSearchMenuService.closeLeftDrawer();
}

ngOnDestroy(): void {
this._unsubscribeAll.next();
this._unsubscribeAll.complete();
}
}
4 changes: 0 additions & 4 deletions src/@noctua.search/services/noctua-review-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ export class NoctuaReviewSearchService {
return this.camsService.replace([this.currentMatchedEnity], replaceWith);
}

bulkEdit(store = false): Observable<any> {
return this.camsService.bulkEdit(store);
}

clear() {
this.matchedEntities = [];
this.matchedCountCursor = 0;
Expand Down

0 comments on commit 2e6f0a5

Please sign in to comment.