Skip to content
Snippets Groups Projects
Commit 507020db authored by Giuseppe's avatar Giuseppe
Browse files

stash for duplicate section

parent 24450f63
No related branches found
No related tags found
No related merge requests found
import { Item } from '../../shared/item.model';
export interface WorkspaceitemSectionDeduplicationObject {
export interface WorkspaceitemSectionDetectDuplicateObject {
matches: {
[itemId: string]: DetectDuplicateMatch;
};
......
......@@ -3,55 +3,48 @@
[object]="object"
></ds-item-list-preview>
<!--<button (click)="toggleSubmitterDecision()"-->
<!--class="btn btn-link">-->
<!--<span *ngIf="isWorkFlow && !showSubmitterDecision"> <i class="fa fa-angle-double-down"></i> Show submitter decision</span>-->
<!--<span *ngIf="isWorkFlow && showSubmitterDecision"> <i class="fa fa-angle-double-up"></i> Hide submitter decision</span>-->
<!--</button>-->
<!--<div *ngIf="showSubmitterDecision">-->
<div>
<label><strong> {{submitterDecisionLabel | async}} </strong>
<span [ngClass]="{'label': true,
'label-warning': match.submitterDecision == 'verify',
'label-success': match.submitterDecision == 'reject',
'label-default': (match.submitterDecision == undefined || match.submitterDecision == null)}">
{{submitterDecisionTxt}}
</span>
</label>
<div *ngIf="isWorkFlow" class="mt-2">
<form>
<div class="form-group mb-2">
<label class="mb-1" for="submitterDecision"><strong> {{'submission.sections.detect-duplicate.submitter-decision' | translate}} </strong></label><br>
<span id="submitterDecision" class="badge badge-pill {{decisionLabelClass}}">
{{submitterDecision$ | async}}
</span>
</div>
<div class="form-group" *ngIf="submitterNote">
<label for="submitterNote"><strong>{{'submission.sections.detect-duplicate.submitter-note' | translate}}</strong></label>
<textarea class="form-control" id="submitterNote" rows="3" readonly>{{submitterNote}}</textarea>
</div>
</form>
</div>
<!--<div>-->
<!--<label><strong> Explaination: </strong>-->
<!--<span class="label">-->
<!--I want to provide the fulltext of this article-->
<!--</span>-->
<!--</label>-->
<!--</div>-->
<div class="mb-3" *ngIf="!hasDecision">
<div class="mt-3 mb-2" *ngIf="!hasDecision">
<button type="button"
class="btn btn-warning"
ngbTooltip="{{'submission.sections.deduplication.duplicated_help' | translate}}"
ngbTooltip="{{'submission.sections.detect-duplicate.duplicate-help' | translate}}"
[disabled]="(processingVerify | async) || (processingReject | async)"
(click)="openModal(modal)">
<span> {{duplicatedBtnLabel | async}}</span>
<span *ngIf="(processingVerify | async)"><i class='fa fa-circle-o-notch fa-spin'></i> {{'submission.workflow.tasks.generic.processing' | translate}}</span>
<span *ngIf="!(processingVerify | async)">{{duplicateBtnLabel$ | async}}</span>
</button>
<button type="button"
class="btn btn-success"
ngbTooltip="{{'submission.sections.deduplication.not_duplicated_help' | translate}}"
ngbTooltip="{{'submission.sections.detect-duplicate.not-duplicate-help' | translate}}"
[disabled]="(processingReject | async) || (processingVerify | async)"
(click)="setAsNotDuplicate()">
<span> {{'submission.sections.deduplication.not_duplicated' | translate}}</span>
<span *ngIf="(processingReject | async)"><i class='fa fa-circle-o-notch fa-spin'></i> {{'submission.workflow.tasks.generic.processing' | translate}}</span>
<span *ngIf="!(processingReject | async)">{{notDuplicateBtnLabel$ | async}}</span>
</button>
</div>
<div class="mb-3" *ngIf="hasDecision">
<div class="mt-3 mb-2" *ngIf="hasDecision">
<button type="button"
class="btn btn-danger"
ngbTooltip="{{'submission.sections.deduplication.clear_decision_help' | translate}}"
ngbTooltip="{{'submission.sections.detect-duplicate.clear-decision-help' | translate}}"
(click)="clearDecision()">
<span> {{'submission.sections.deduplication.clear_decision' | translate}}</span>
<span> {{'submission.sections.detect-duplicate.clear-decision' | translate}}</span>
</button>
</div>
......@@ -67,18 +60,19 @@
</div>
<div class="modal-body">
<div class="alert alert-info" role="alert">
{{'submission.sections.deduplication.note_help' | translate}}
{{'submission.sections.detect-duplicate.note-help' | translate}}
</div>
<form (ngSubmit)="setAsDuplicate();" [formGroup]="rejectForm" >
<textarea class="w-100"
formControlName="reason"
rows="4"
placeholder="{{'submission.sections.deduplication.note_placeholder' | translate}}"></textarea>
placeholder="{{'submission.sections.detect-duplicate.note-placeholder' | translate}}"></textarea>
<button id="btn-chat"
class="btn btn-danger btn-lg btn-block mt-3"
[disabled]="!rejectForm.valid"
type="submit">
<span>{{'submission.sections.deduplication.duplicated' | translate}}</span>
<span *ngIf="(processingReject | async)"><i class='fa fa-circle-o-notch fa-spin'></i> {{'submission.workflow.tasks.generic.processing' | translate}}</span>
<span *ngIf="!(processingReject | async)">{{'submission.sections.detect-duplicate.duplicate' | translate}}</span>
</button>
</form>
</div>
......
......@@ -4,9 +4,7 @@ import { DetectDuplicateMatch } from '../../../../core/submission/models/workspa
import { SubmissionService } from '../../../submission.service';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Store } from '@ngrx/store';
import { SubmissionState } from '../../../submission.reducers';
import { DeduplicationService } from '../deduplication.service';
import { DetectDuplicateService } from '../detect-duplicate.service';
import { JsonPatchOperationsBuilder } from '../../../../core/json-patch/builder/json-patch-operations-builder';
import { JsonPatchOperationPathCombiner } from '../../../../core/json-patch/builder/json-patch-operation-path-combiner';
import { TranslateService } from '@ngx-translate/core';
......@@ -15,9 +13,8 @@ import { SubmissionScopeType } from '../../../../core/submission/submission-scop
import { DuplicateDecisionValue } from '../models/duplicate-decision-value';
import { DuplicateDecision } from '../models/duplicate-decision.model';
import { DuplicateDecisionType } from '../models/duplicate-decision-type';
import { SaveSubmissionSectionFormAction } from '../../../objects/submission-objects.actions';
import { match } from 'minimatch';
import { isNotEmpty } from '../../../../shared/empty.util';
import { SectionsService } from '../../sections.service';
@Component({
selector: 'ds-duplicate-match',
......@@ -36,7 +33,8 @@ export class DuplicateMatchComponent implements OnInit {
isWorkFlow = false;
showSubmitterDecision = false;
decisionType: DuplicateDecisionType;
submitterDecisionTxt: string;
submitterDecision$: Observable<string>;
submitterNote: string;
hasDecision: boolean;
......@@ -44,16 +42,18 @@ export class DuplicateMatchComponent implements OnInit {
rejectForm: FormGroup;
modalRef: NgbModalRef;
pathCombiner: JsonPatchOperationPathCombiner;
public processingVerify: Observable<boolean> = Observable.of(false);
public processingReject: Observable<boolean> = Observable.of(false);
decisionLabelClass: string;
duplicateBtnLabel$: Observable<string>;
notDuplicateBtnLabel$: Observable<string>;
duplicatedBtnLabel: Observable<string>;
submitterDecisionLabel: Observable<string>;
constructor(private deduplicationService: DeduplicationService,
private submissionService: SubmissionService,
private modalService: NgbModal,
constructor(private detectDuplicateService: DetectDuplicateService,
private formBuilder: FormBuilder,
private store: Store<SubmissionState>,
protected operationsBuilder: JsonPatchOperationsBuilder,
private modalService: NgbModal,
private operationsBuilder: JsonPatchOperationsBuilder,
private sectionService: SectionsService,
private submissionService: SubmissionService,
private translate: TranslateService) {
}
......@@ -72,51 +72,55 @@ export class DuplicateMatchComponent implements OnInit {
: this.match.submitterDecision !== null;
if (this.match.submitterDecision) {
if (this.match.submitterDecision === 'verify') {
this.submitterDecisionTxt = 'It\'s a duplicate';
} else {
this.submitterDecisionTxt = 'It\'s not a duplicate';
}
this.submitterDecision$ = (this.match.submitterDecision === DuplicateDecisionValue.Reject) ?
this.translate.get('submission.sections.detect-duplicate.not-duplicate') :
this.translate.get('submission.sections.detect-duplicate.duplicate');
this.decisionLabelClass = (this.match.submitterDecision === DuplicateDecisionValue.Reject) ? 'badge-success' : 'badge-warning';
this.submitterNote = this.match.submitterNote;
} else {
this.submitterDecisionTxt = 'Not decided';
this.submitterDecision$ = this.translate.get('submission.sections.detect-duplicate.no-decision');
this.decisionLabelClass = 'badge-light';
}
this.pathCombiner = new JsonPatchOperationPathCombiner('sections', this.sectionId);
this.duplicatedBtnLabel = this.isWorkFlow ?
this.translate.get('submission.sections.deduplication.duplicated_ctrl')
: this.translate.get('submission.sections.deduplication.duplicated');
this.duplicateBtnLabel$ = this.isWorkFlow ?
((this.match.submitterDecision === DuplicateDecisionValue.Verify) ?
this.translate.get('submission.sections.detect-duplicate.confirm-duplicate') :
this.translate.get('submission.sections.detect-duplicate.duplicate-ctrl'))
: this.translate.get('submission.sections.detect-duplicate.duplicate');
this.submitterDecisionLabel = this.isWorkFlow ?
this.translate.get('submission.sections.deduplication.submitter_decision')
: this.translate.get('submission.sections.deduplication.your_decision');
this.notDuplicateBtnLabel$ = (this.isWorkFlow && this.match.submitterDecision === DuplicateDecisionValue.Reject) ?
this.translate.get('submission.sections.detect-duplicate.confirm-not-duplicate') :
this.translate.get('submission.sections.detect-duplicate.not-duplicate');
}
setAsDuplicate() {
this.processingVerify = Observable.of(true);
const decision = new DuplicateDecision(
DuplicateDecisionValue.Verify,
this.decisionType,
this.rejectForm.get('reason').value);
console.log('Setting item #' + this.item.uuid + ' as duplicated...');
this.dispatchAction(decision);
this.modalRef.dismiss();
}
setAsNotDuplicate() {
this.processingReject = Observable.of(true);
const decision = new DuplicateDecision(
DuplicateDecisionValue.Reject,
this.decisionType);
console.log('Setting item #' + this.item.uuid + ' as not duplicated...');
this.dispatchAction(decision);
}
clearDecision() {
console.log('Clearing item #' + this.item.uuid + ' from previous decision...');
const decision = new DuplicateDecision(
DuplicateDecisionValue.Undo,
this.decisionType);
console.log('Setting item #' + this.item.uuid + ' as not duplicated...');
this.dispatchAction(decision);
}
......@@ -128,50 +132,15 @@ export class DuplicateMatchComponent implements OnInit {
note: isNotEmpty(decision.note) ? decision.note : null
};
this.operationsBuilder.add(this.pathCombiner.getPath(pathDecision), payload, false, true);
this.store.dispatch(new SaveSubmissionSectionFormAction(this.submissionId, this.sectionId));
// Call workflow action
// const decision = clear ? null : duplicate ? 'verify' : 'reject';
// const pathDecision = this.isWorkFlow ? 'workflowDecision' : 'submitterDecision';
// this.operationsBuilder.add(this.pathCombiner.getPath(pathDecision), decision, false, true);
//
// if (!clear && duplicate) {
// const note = this.rejectForm.get('reason').value;
// const pathNote = this.isWorkFlow ? 'workflowNote' : 'submitterNote';
// this.operationsBuilder.add(this.pathCombiner.getPath(pathNote), note, false, true);
// }
// const now = new Date();
// const time = now.getUTCFullYear() + '/' + now.getUTCMonth() + 1 + '/' + now.getDay();
// if (this.isWorkFlow) {
// // Call workflow action
// payload.data.workflowDecision = clear ? null : duplicated ? 'verify' : 'reject';
// // payload.data.workflowTime = time;
// if (!clear && duplicated) {
// const note = this.rejectForm.get('reason').value;
// payload.data.workflowNote = note;
// }
// // Dispatch WorkFLOW action
// // this.store.dispatch(new SetWorkflowDuplicatedAction(payload));
// const path = 'workflowDecision'
// this.operationsBuilder.add(this.pathCombiner.getPath(path), payload.data.workflowDecision, false, true);
//
// } else {
// // Call workspace action
// payload.data.submitterDecision = clear ? null : duplicated ? 'verify' : 'reject';
// // payload.data.submitterTime = time;
// if (!clear && duplicated) {
// const note = this.rejectForm.get('reason').value;
// payload.data.submitterNote = note;
// }
// // Dispatch workSPACE action
// this.store.dispatch(new SetWorkspaceDuplicatedAction(payload));
// }
}
// dispatch patch operation only when section is active
this.sectionService.isSectionActive(this.submissionId, this.sectionId)
.filter((isActive: boolean) => isActive)
.take(1)
.subscribe(() => {
this.operationsBuilder.add(this.pathCombiner.getPath(pathDecision), payload, false, true);
this.detectDuplicateService.saveDuplicateDecision(this.submissionId, this.sectionId)
});
toggleSubmitterDecision() {
this.showSubmitterDecision = !this.showSubmitterDecision;
}
openModal(modal) {
......
<ds-loading *ngIf="isLoading" message="Loading..."></ds-loading>
<ng-container *ngIf="(sectionData$ | async)?.matches.length == 0">
<div class="row">
<div class="col-md-12">
<h3 class="text-center"><span class="text-muted">No duplicated yet.</span></h3>
</div>
</div>
<ng-container *ngIf="(totalMatch$ | async) === 0">
<ds-alert [type]="AlertTypeEnum.Info" [content]="('submission.sections.detect-duplicate.disclaimer-no-match' | translate)"></ds-alert>
</ng-container>
<ng-container
*ngIf="(totalMatch$ | async) > 0">
<div class="alert alert-danger" role="alert">
{{ disclaimer | async }}
</div>
<ng-container *ngIf="(totalMatch$ | async) > 0">
<ds-alert [type]="AlertTypeEnum.Warning" [content]="(disclaimer | async)"></ds-alert>
<ds-pagination
[paginationOptions]="config"
......
import { SectionsType } from '../sections-type';
import { ChangeDetectionStrategy, Component, Inject, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Inject, OnDestroy } from '@angular/core';
import { SectionModelComponent } from '../models/section.model';
import { renderSectionFor } from '../sections-decorator';
import { SectionDataObject } from '../models/section-data.model';
import { SubmissionState } from '../../submission.reducers';
import { Store } from '@ngrx/store';
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
import { submissionSectionDataFromIdSelector } from '../../selectors';
import { Observable } from 'rxjs/Observable';
import { isNotEmpty } from '../../../shared/empty.util';
import { TranslateService } from '@ngx-translate/core';
import { SubmissionService } from '../../submission.service';
import { SubmissionScopeType } from '../../../core/submission/submission-scope-type';
import { AlertType } from '../../../shared/alerts/aletrs-type';
import { DetectDuplicateService } from './detect-duplicate.service';
import { SectionsService } from '../sections.service';
import { Subscription } from 'rxjs/Subscription';
import { hasValue } from '../../../shared/empty.util';
@Component({
selector: 'ds-deduplication-section',
......@@ -22,7 +23,8 @@ import { SubmissionScopeType } from '../../../core/submission/submission-scope-t
})
@renderSectionFor(SectionsType.DetectDuplicate)
export class DetectDuplicateSectionComponent extends SectionModelComponent implements OnInit {
export class DetectDuplicateSectionComponent extends SectionModelComponent implements OnDestroy {
public AlertTypeEnum = AlertType;
public isLoading = true;
public sectionData$: Observable<any>;
public matches = {};
......@@ -33,44 +35,57 @@ export class DetectDuplicateSectionComponent extends SectionModelComponent imple
isWorkFlow = false;
disclaimer: Observable<string>;
sub: Subscription;
constructor(protected store: Store<SubmissionState>,
private translate: TranslateService,
private submissionService: SubmissionService,
constructor(protected detectDuplicateService: DetectDuplicateService,
protected translate: TranslateService,
protected sectionService: SectionsService,
protected submissionService: SubmissionService,
@Inject('collectionIdProvider') public injectedCollectionId: string,
@Inject('sectionDataProvider') public injectedSectionData: SectionDataObject,
@Inject('submissionIdProvider') public injectedSubmissionId: string) {
super(injectedCollectionId, injectedSectionData, injectedSubmissionId);
}
ngOnInit() {
onSectionInit() {
this.config = new PaginationComponentOptions();
this.config.id = 'duplicated_items';
this.config.pageSize = 2;
this.sortConfig = new SortOptions('dc.title', SortDirection.ASC);
this.sectionData$ = this.store.select(submissionSectionDataFromIdSelector(this.submissionId, this.sectionData.id))
.filter((sd) => isNotEmpty(sd))
.startWith({matches: {}})
.distinctUntilChanged();
this.sectionData$ = this.detectDuplicateService.getDuplicateMatches(this.submissionId, this.sectionData.id);
this.totalMatch$ = this.store.select(submissionSectionDataFromIdSelector(this.submissionId, this.sectionData.id))
.filter((sd) => isNotEmpty(sd))
.startWith({matches: {}})
.map((sd) => Object.keys(sd.matches).length)
.distinctUntilChanged();
this.totalMatch$ = this.detectDuplicateService.getDuplicateTotalMatches(this.submissionId, this.sectionData.id);
this.isWorkFlow = this.submissionService.getSubmissionScope() === SubmissionScopeType.WorkflowItem;
this.disclaimer = this.isWorkFlow ?
this.translate.get('submission.sections.deduplication.disclaimer_ctrl')
: this.translate.get('submission.sections.deduplication.disclaimer');
this.translate.get('submission.sections.detect-duplicate.disclaimer-ctrl')
: this.translate.get('submission.sections.detect-duplicate.disclaimer');
this.isLoading = false;
this.sub = this.totalMatch$
.map((totalMatches: number) => totalMatches === 0)
.distinctUntilChanged()
.subscribe((status: boolean) => {
this.sectionService.setSectionStatus(this.submissionId, this.sectionData.id, status);
})
}
protected getSectionStatus(): Observable<boolean> {
return this.totalMatch$
.map((totalMatches: number) => totalMatches === 0);
}
setPage(page) {
this.config.currentPage = page;
}
ngOnDestroy(): void {
if (hasValue(this.sub)) {
this.sub.unsubscribe();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment