#8834: Home page: Drafts query for both Datasets and DMPs.

1. recent-activity-criteria.ts: Added in RecentActivityCriteria optional field "public status?: Number;" (to get only drafts).
2. drafts.component.ts & drafts.component.html: Updated calls and display to query for both Datasets and DMPs (same as recent-edited-activity, but include only drafts).
4. recent-edited-activity.component.ts: Removed old unnecessary logs.
This commit is contained in:
Konstantina Galouni 2023-07-17 18:04:39 +03:00
parent aec7126fd3
commit 77f40570ac
4 changed files with 630 additions and 369 deletions

View File

@ -2,5 +2,6 @@ import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order
import { BaseCriteria } from '../base-criteria'; import { BaseCriteria } from '../base-criteria';
export class RecentActivityCriteria extends BaseCriteria{ export class RecentActivityCriteria extends BaseCriteria{
public status?: Number;
public order: RecentActivityOrder = RecentActivityOrder.MODIFIED; public order: RecentActivityOrder = RecentActivityOrder.MODIFIED;
} }

View File

@ -1,4 +1,7 @@
<div id="drafts" #drafts> <div class="col-md-12 d-flex justify-content-center" *ngIf="allRecentActivities == null">
<span class="empty-list">{{'DMP-LISTING.EMPTY-LIST' | translate}}</span>
</div>
<div *ngIf="allRecentActivities != null" id="results" #results>
<div class="d-flex flex-direction-row pt-4"> <div class="d-flex flex-direction-row pt-4">
<!-- Sort by --> <!-- Sort by -->
<span class="d-flex align-items-center">{{'DMP-LISTING.SORT-BY' | translate}}:</span> <span class="d-flex align-items-center">{{'DMP-LISTING.SORT-BY' | translate}}:</span>
@ -12,118 +15,157 @@
</mat-form-field> </mat-form-field>
<!-- End of Sort by --> <!-- End of Sort by -->
<!-- Search Filter--> <!-- Search Filter-->
<mat-form-field *ngIf="datasetDrafts" appearance="outline" class="search-form ml-auto col-auto pr-0" floatLabel="never"> <mat-form-field appearance="outline" class="search-form ml-auto col-auto pr-0" floatLabel="never">
<mat-icon matSuffix>search</mat-icon> <mat-icon matSuffix>search</mat-icon>
<input matInput placeholder="{{'CRITERIA.DATA-SETS.DRAFT-LIKE'| translate}}" name="likeCriteria" [formControl]="formGroup.get('like')"> <input matInput placeholder="{{'CRITERIA.LIKE'| translate}}" name="likeCriteria" [formControl]="formGroup.get('like')">
<mat-error *ngIf="formGroup.get('like').hasError('backendError')">{{formGroup.get('like').getError('backendError').message}}</mat-error> <mat-error *ngIf="formGroup.get('like').hasError('backendError')">{{formGroup.get('like').getError('backendError').message}}</mat-error>
</mat-form-field> </mat-form-field>
<!-- End of Search Filter --> <!-- End of Search Filter -->
</div> </div>
<div *ngIf="datasetDrafts && datasetDrafts.length > 0 && page > 1" class="d-flex justify-content-center"> <div *ngIf="allRecentActivities && allRecentActivities.length > 0 && page > 1" class="d-flex justify-content-center">
<button type="button" class="btn-load-more" (click)="loadNextOrPrevious(false)">{{'GENERAL.ACTIONS.LOAD-LESS' | translate}}</button> <button type="button" class="btn-load-more" (click)="loadNextOrPrevious(false)">{{'GENERAL.ACTIONS.LOAD-LESS' | translate}}</button>
</div> </div>
<div *ngFor="let activity of datasetDrafts"> <div *ngFor="let activity of allRecentActivities">
<div class="dataset-card"> <div *ngIf="activity && activity.type === recentActivityTypeEnum.Dmp.valueOf()">
<a [routerLink]="['../datasets/overview/' + activity.id]" class="pointer"> <div class="dmp-card">
<div class="d-flex flex-direction-row"> <!-- <a (click)="redirect(activity.id, activity.type)" class="pointer"> -->
<div class="col-auto dataset-label">{{'DATASET-LISTING.DATASET-DESCRIPTION' | translate}}</div> <a [routerLink]="navigateToUrl(activity.id, activity.type)" class="pointer">
<div class="col-auto ml-auto edited-date">{{'DATASET-LISTING.STATES.EDITED' | translate}}: {{activity.modified | dateTimeCultureFormatter: "d MMMM y"}}</div> <div class="d-flex flex-direction-row">
</div> <div class="col-auto dmp-label">{{ 'DMP-LISTING.DMP' | translate }}</div>
<div class="col-auto dataset-title-draft">{{activity.label}}</div> <div *ngIf="!publicMode" class="col-auto ml-auto edited-date">{{ 'DMP-LISTING.EDITED' | translate }}: {{ activity.modified | dateTimeCultureFormatter: "d MMMM y" }}</div>
<div class="dataset-subtitle"> <div *ngIf="publicMode" class="col-auto ml-auto edited-date">{{ 'DMP-LISTING.PUBLISHED' | translate }}: {{ activity.publishedAt | dateTimeCultureFormatter: "d MMMM y" }}</div>
<span class="col-auto">{{ roleDisplay(activity.users) }}</span>
<span>.</span>
<span class="col-auto" *ngIf="activity.status === 1 && activity.public === true"><span class="material-icons icon-align">public</span>{{'DATASET-LISTING.STATES.PUBLIC' | translate}}</span>
<span *ngIf="activity.status === 1 && activity.public === false" class="col-auto"><span class="material-icons icon-align">done</span>{{ enumUtils.toDmpStatusString(activity.status) }}</span>
<span *ngIf="activity.status === 0" class=" col-auto draft"><span class="material-icons icon-align">create</span>{{ enumUtils.toDmpStatusString(activity.status) }}</span>
<span>.</span>
<span class="col">{{'DATASET-LISTING.COLUMNS.GRANT' | translate}}: {{activity.grant}}</span>
</div>
<div class="d-flex flex-direction-row pt-3 pb-3">
<div class="col-auto dataset-subtitle pr-0">{{'DATASET-LISTING.TOOLTIP.PART-OF' | translate}}
<div class="col-auto dmp-label ml-3">{{'DATASET-LISTING.TOOLTIP.DMP' | translate}}</div>
</div> </div>
<!-- <div class="col-auto dmp-label">{{'DATASET-LISTING.TOOLTIP.DMP' | translate}}</div> --> <div class="col-auto dmp-title-draft">{{activity.title}}</div>
<div class="col dmp-title">{{activity.dmp}}</div> <div class="dmp-subtitle">
<span class="col-auto">{{ roleDisplay(activity.users) }}</span>
<span>.</span>
<span class=" col-auto draft"><span class="material-icons icon-align">create</span>{{ enumUtils.toDmpStatusString(activity.status) }}</span>
<span>.</span>
<span class="col-auto">{{'DMP-LISTING.VERSION' | translate}} {{activity.version}}</span>
<span>.</span>
<span class="col">{{ 'DMP-LISTING.GRANT' | translate }}: {{activity.grant}}</span>
</div>
<div class="col-auto dmp-dataset-descriptions-title">{{'DMP-LISTING.CONTAINED-DATASETS' | translate}}: ({{ getDatasets(activity).length }})
</div>
<div *ngFor="let dataset of getDatasets(activity); let i = index; let last = last" [ngClass]="{'pb-3': i === activity.datasets.length - 1}">
<div *ngIf="i < 3">
<div class="col-auto dmp-dataset-descriptions-name" *ngIf="!last && i !== 2">{{dataset.label}},</div>
<div class="col-auto dmp-dataset-descriptions-name" *ngIf="last || i == 2">{{dataset.label}}</div>
</div>
</div>
<!-- <a class="d-flex justify-content-center pb-3 show-more" *ngIf="getDatasets(activity).length > 3" (click)="redirect(activity.id, activity.type)"><u>{{'GENERAL.ACTIONS.SHOW-MORE' | translate}}</u></a> -->
<a class="d-flex justify-content-center pb-3 show-more" *ngIf="getDatasets(activity).length > 3" [routerLink]="navigateToUrl(activity.id, activity.type)"><u>{{'GENERAL.ACTIONS.SHOW-MORE' | translate}}</u></a>
</a>
<div class="dmp-card-actions">
<a class="col-auto border-right pointer" [matMenuTriggerFor]="exportMenu"><span class="material-icons icon-align pr-2">open_in_new</span>{{'DMP-LISTING.ACTIONS.EXPORT' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isDraftDmp(activity)" [routerLink]="['/datasets/new/' + activity.id]" target="_blank"><span class="material-icons icon-align">add</span>{{'DMP-LISTING.ACTIONS.ADD-DATASET-SHORT' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isUserOwner(activity)" (click)="openShareDialog(activity.id, activity.title)"><span class="material-icons icon-align pr-2">group_add</span>{{'DMP-LISTING.ACTIONS.INVITE-SHORT' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isAuthenticated()" (click)="cloneOrNewVersionClicked(activity, false)"><span class="material-icons icon-align pr-2">filter_none</span>{{'DMP-LISTING.ACTIONS.CLONE' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="!isAuthenticated()" (click)="viewVersions(getGroupId(activity), activity.title, activity)"><span class="material-icons icon-align pr-2">library_books</span>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="!isDraftDmp(activity) && isUserOwner(activity)" (click)="deleteDmpClicked(activity)"><span class="material-icons icon-align pr-2">delete</span>{{ 'DMP-LISTING.ACTIONS.DELETE' | translate }}</a>
<a class="col-auto pointer" *ngIf="isAuthenticated()" [matMenuTriggerFor]="actionsMenu"><span class="material-icons icon-align pl-2">more_horiz</span></a>
</div> </div>
</a>
<div class="dataset-card-actions">
<a class="col-auto border-right pointer" [matMenuTriggerFor]="exportMenu"><span class="material-icons icon-align pr-2">open_in_new</span>{{'DATASET-LISTING.ACTIONS.EXPORT' | translate}}</a>
<a class="col-auto border-right pointer" (click)="openShareDialog(activity.dmpId, activity.dmp)"><span class="material-icons icon-align pr-2">group_add</span>{{'DATASET-LISTING.ACTIONS.INVITE-SHORT' | translate}}</a>
<a class="col-auto border-right pointer" (click)="openDmpSearchDialogue(activity)"><span class="material-icons icon-align pr-2">file_copy</span>{{'DATASET-WIZARD.ACTIONS.COPY-DATASET' | translate}}</a>
<a class="col-auto border-right pointer" (click)="deleteClicked(activity.id)"><span class="material-icons icon-align pr-2">delete</span>{{ 'DATASET-WIZARD.ACTIONS.DELETE' | translate }}</a>
<!-- <a class="col-auto pointer" [matMenuTriggerFor]="actionsMenu"><span class="material-icons icon-align pl-2">more_horiz</span></a> --> <mat-menu #exportMenu="matMenu" xPosition="before">
<!-- <a class="col-auto" [matMenuTriggerFor]="actionsMenu" *ngIf="!publicMode"><span class="material-icons icon-align pl-2">more_horiz</span></a> --> <button mat-menu-item (click)="downloadPdf(activity.id)">
<i class="fa fa-file-pdf-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.PDF' | translate}}</span>
</button>
<button mat-menu-item (click)="downloadDocx(activity.id)">
<i class="fa fa-file-word-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.DOC' | translate}}</span>
</button>
<button mat-menu-item (click)="downloadXml(activity.id)">
<i class="fa fa-file-code-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.XML' | translate}}</span>
</button>
<button mat-menu-item (click)="downloadJson(activity.id)">
<i class="fa fa-file-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.JSON' | translate}}</span>
</button>
</mat-menu>
<mat-menu #actionsMenu="matMenu" xPosition="before">
<button *ngIf="isUserOwner(activity)" mat-menu-item (click)="cloneOrNewVersionClicked(activity, true)">
<mat-icon>queue</mat-icon>{{'DMP-LISTING.ACTIONS.NEW-VERSION' | translate}}
</button>
<button mat-menu-item (click)="viewVersions(getGroupId(activity), activity.title, activity)">
<mat-icon>library_books</mat-icon>{{'DMP-LISTING.ACTIONS.VIEW-VERSION' | translate}}
</button>
<button mat-menu-item *ngIf="isDraftDmp(activity) && isUserOwner(activity)" (click)="deleteDmpClicked(activity)" class="menu-item">
<mat-icon>delete</mat-icon>{{ 'DMP-LISTING.ACTIONS.DELETE' | translate }}
</button>
</mat-menu>
</div> </div>
<mat-menu #actionsMenu="matMenu"> </div>
<button mat-menu-item (click)="openDmpSearchDialogue(activity)" class="menu-item"> <div *ngIf="activity && activity.type === recentActivityTypeEnum.Dataset.valueOf()">
<mat-icon>file_copy</mat-icon>{{'DATASET-WIZARD.ACTIONS.COPY-DATASET' | translate}} <div class="dataset-card">
</button> <!-- <a (click)="redirect(activity.id, activity.type)" class="pointer"> -->
<button mat-menu-item (click)="deleteClicked(activity.id)" class="menu-item"> <a [routerLink]="navigateToUrl(activity.id, activity.type)" class="pointer">
<mat-icon>delete</mat-icon>{{ 'DATASET-WIZARD.ACTIONS.DELETE' | translate }} <div class="d-flex flex-direction-row">
</button> <div class="col-auto dataset-label">{{'DATASET-LISTING.DATASET-DESCRIPTION' | translate}}</div>
<!-- <button mat-menu-item *ngIf="needsUpdate(activity)" class="menu-item" (click)="openUpdateDatasetProfileDialogue(activity.id);"> <div *ngIf="!publicMode" class="col-auto ml-auto edited-date">{{'DATASET-LISTING.STATES.EDITED' | translate}}: {{activity.modified | dateTimeCultureFormatter: "d MMMM y"}}</div>
<mat-icon>update</mat-icon> <div *ngIf="publicMode" class="col-auto ml-auto edited-date">{{'DATASET-LISTING.STATES.PUBLISHED' | translate}}: {{activity.publishedAt | dateTimeCultureFormatter: "d MMMM y"}}</div>
{{ 'DATASET-WIZARD.ACTIONS.UPDATE-DATASET-PROFILE' | translate }} </div>
</button> --> <div class="col-auto dataset-title-draft">{{activity.title}}</div>
</mat-menu> <div class="dataset-subtitle">
<span class="col-auto">{{ roleDisplay(activity.users) }}</span>
<span>.</span>
<span class=" col-auto draft"><span class="material-icons icon-align">create</span>{{ enumUtils.toDmpStatusString(activity.status) }}</span>
<span>.</span>
<span class="col">{{'DATASET-LISTING.COLUMNS.GRANT' | translate}}: {{activity.grant}}</span>
</div>
<div class="d-flex flex-direction-row pt-3 pb-3">
<div class="col-auto dataset-subtitle pr-0">{{'DATASET-LISTING.TOOLTIP.PART-OF' | translate}}
<div class="col-auto dmp-label ml-3">{{'DATASET-LISTING.TOOLTIP.DMP' | translate}}</div>
</div>
<!-- <div class="col-auto dmp-label">{{'DATASET-LISTING.TOOLTIP.DMP' | translate}}</div> -->
<div class="col dmp-title">{{ getDmp(activity) }}</div>
</div>
</a>
<div class="dataset-card-actions">
<a class="col-auto border-right pointer" [matMenuTriggerFor]="exportMenu"><span class="material-icons icon-align pr-2">open_in_new</span>{{'DATASET-LISTING.ACTIONS.EXPORT' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isAuthenticated()" (click)="openShareDialog(getDmpId(activity), getDmp(activity))"><span class="material-icons icon-align pr-2">group_add</span>{{'DATASET-LISTING.ACTIONS.INVITE-SHORT' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isAuthenticated()" (click)="openDmpSearchDialogue(activity)"><span class="material-icons icon-align pr-2">file_copy</span>{{'DATASET-WIZARD.ACTIONS.COPY-DATASET' | translate}}</a>
<a class="col-auto border-right pointer" *ngIf="isAuthenticated()" (click)="deleteDatasetClicked(activity.id)"><span class="material-icons icon-align pr-2">delete</span>{{ 'DATASET-WIZARD.ACTIONS.DELETE' | translate }}</a>
<mat-menu #exportMenu="matMenu" xPosition="before"> <!-- <a class="col-auto pointer" [matMenuTriggerFor]="actionsMenu"><span class="material-icons icon-align pl-2">more_horiz</span></a> -->
<button mat-menu-item (click)="downloadPDF(activity)"> <!-- <a class="col-auto" [matMenuTriggerFor]="actionsMenu" *ngIf="!publicMode"><span class="material-icons icon-align pl-2">more_horiz</span></a> -->
<i class="fa fa-file-pdf-o pr-2"></i> </div>
<span>{{'GENERAL.FILE-TYPES.PDF' | translate}}</span> <mat-menu #actionsMenu="matMenu">
</button> <button mat-menu-item (click)="openDmpSearchDialogue(activity)" class="menu-item">
<button mat-menu-item (click)="downloadDOCX(activity)"> <mat-icon>file_copy</mat-icon>{{'DATASET-WIZARD.ACTIONS.COPY-DATASET' | translate}}
<i class="fa fa-file-word-o pr-2"></i> </button>
<span>{{'GENERAL.FILE-TYPES.DOC' | translate}}</span> <button mat-menu-item (click)="deleteDatasetClicked(activity.id)" class="menu-item">
</button> <mat-icon>delete</mat-icon>{{ 'DATASET-WIZARD.ACTIONS.DELETE' | translate }}
<button mat-menu-item (click)="downloadXML(activity)"> </button>
<i class="fa fa-file-code-o pr-2"></i> <!-- <button mat-menu-item *ngIf="needsUpdate(activity)" class="menu-item" (click)="openUpdateDatasetProfileDialogue(activity.id);">
<span>{{'GENERAL.FILE-TYPES.XML' | translate}}</span> <mat-icon>update</mat-icon>
</button> {{ 'DATASET-WIZARD.ACTIONS.UPDATE-DATASET-PROFILE' | translate }}
</mat-menu> </button> -->
</mat-menu>
<mat-menu #exportMenu="matMenu" xPosition="before">
<button mat-menu-item (click)="downloadPDF(activity)">
<i class="fa fa-file-pdf-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.PDF' | translate}}</span>
</button>
<button mat-menu-item (click)="downloadDOCX(activity)">
<i class="fa fa-file-word-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.DOC' | translate}}</span>
</button>
<button mat-menu-item (click)="downloadXML(activity)">
<i class="fa fa-file-code-o pr-2"></i>
<span>{{'GENERAL.FILE-TYPES.XML' | translate}}</span>
</button>
</mat-menu>
</div>
</div> </div>
</div> </div>
<div class="text-muted d-flex justify-content-center mt-5" *ngIf="!hasMoreResults && datasetDrafts && datasetDrafts.length > 0"> <div class="text-muted d-flex justify-content-center mt-5" *ngIf="!hasMoreActivity && allRecentActivities && allRecentActivities.length > 0">
{{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}} {{'GENERAL.ACTIONS.NO-MORE-AVAILABLE' | translate}}
</div> </div>
<div *ngIf="datasetDrafts && datasetDrafts.length > 0 && datasetDrafts.length >= pageSize && hasMoreResults" class="d-flex justify-content-center"> <div *ngIf="allRecentActivities && allRecentActivities.length > 0 && (allRecentActivities.length >= startIndex + pageSize) && hasMoreActivity" class="d-flex justify-content-center">
<button type="button" class="btn-load-more" (click)="loadNextOrPrevious()">{{'GENERAL.ACTIONS.LOAD-MORE' | translate}}</button> <button type="button" class="btn-load-more" (click)="loadNextOrPrevious()">{{'GENERAL.ACTIONS.LOAD-MORE' | translate}}</button>
</div> </div>
</div> </div>
<!-- <div class="card card-draft">
<div class="card-header card-header-plain">
<div class="card-desc">
<h4 class="card-title">{{ 'TYPES.DATASET-STATUS.DRAFT' | translate }}</h4>
<p class="card-category">{{ 'TYPES.DATASET-STATUS.DRAFT-DESC' | translate }}</p>
</div>
<a class="view-all" [class.clickable]="isAuthenticated()" [routerLink]="['/datasets']" [queryParams]="{status: 0}">{{ 'GENERAL.ACTIONS.VIEW-ALL' | translate}}</a>
</div>
<div class="card-body table-responsive">
<table class="table table-hover">
<tbody *ngIf="datasetDrafts != null">
<tr *ngFor="let dataset of datasetDrafts" (click)="redirect(dataset.id, datasetDraftsTypeEnum.Dataset)" style="cursor: pointer;">
<td>
<div class="row">
<div class="col-md-2">
<i class="material-icons-outlined grey">library_books</i>
</div>
<div class="col-md-10">
<div class="draft-title">
{{'GENERAL.NAMES.DATASET' | translate}}: {{ dataset.label }} {{'DRAFTS.FOR-DMP' | translate}} {{ dataset.dmp }} {{'DRAFTS.FOR-GRANT' | translate}} {{ dataset.grant }}
</div>
<div class="draft-subtitle">{{ dataset.created | date: "shortDate"}}</div>
<div class="draft-desc">{{ dataset.description }}</div>
<div matTooltip="{{ dataset.profile }}" class="grant-pill">{{ dataset.profile }}</div>
</div>
</div>
</td>
</tr>
</tbody>
<tbody *ngIf="datasetDrafts == null">
<td></td>
</tbody>
</table>
</div>
</div> -->

View File

@ -1,6 +1,6 @@
import {Component, OnInit, Input, EventEmitter, Output, ViewChild} from '@angular/core'; import {Component, OnInit, Input, EventEmitter, Output, ViewChild} from '@angular/core';
import { DatasetService } from '../../../core/services/dataset/dataset.service'; import { DatasetService } from '../../../core/services/dataset/dataset.service';
import { DataTableRequest } from '../../../core/model/data-table/data-table-request'; import {DataTableMultiTypeRequest, DataTableRequest} from '../../../core/model/data-table/data-table-request';
import { DatasetCriteria } from '../../../core/query/dataset/dataset-criteria'; import { DatasetCriteria } from '../../../core/query/dataset/dataset-criteria';
import { DatasetListingModel } from '../../../core/model/dataset/dataset-listing'; import { DatasetListingModel } from '../../../core/model/dataset/dataset-listing';
import { AuthService } from '../../../core/services/auth/auth.service'; import { AuthService } from '../../../core/services/auth/auth.service';
@ -9,10 +9,10 @@ import {ActivatedRoute, Router} from '@angular/router';
import { DmpStatus } from '../../../core/common/enum/dmp-status'; import { DmpStatus } from '../../../core/common/enum/dmp-status';
import { Principal } from '@app/core/model/auth/principal'; import { Principal } from '@app/core/model/auth/principal';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { debounceTime, takeUntil } from 'rxjs/operators'; import {debounceTime, map, takeUntil} from 'rxjs/operators';
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
import { DatasetCopyDialogueComponent } from '@app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component'; import { DatasetCopyDialogueComponent } from '@app/ui/dataset/dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component';
import { FormControl, FormBuilder } from '@angular/forms'; import {FormControl, FormBuilder, FormGroup} from '@angular/forms';
import { BaseComponent } from '@common/base/base.component'; import { BaseComponent } from '@common/base/base.component';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service'; import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
@ -27,6 +27,21 @@ import { Role } from '@app/core/common/enum/role';
import { LockService } from '@app/core/services/lock/lock.service'; import { LockService } from '@app/core/services/lock/lock.service';
import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { MatomoService } from '@app/core/services/matomo/matomo-service';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import {RecentActivityModel} from "@app/core/model/recent-activity/recent-activity.model";
import {DmpEditorModel} from "@app/ui/dmp/editor/dmp-editor.model";
import {DmpService} from "@app/core/services/dmp/dmp.service";
import {DashboardService} from "@app/core/services/dashboard/dashboard.service";
import {RecentActivityCriteria} from "@app/core/query/recent-activity/recent-activity-criteria";
import {RecentDmpModel} from "@app/core/model/recent-activity/recent-dmp-activity.model";
import {DatasetUrlListing} from "@app/core/model/dataset/dataset-url-listing";
import {RecentDatasetModel} from "@app/core/model/recent-activity/recent-dataset-activity.model";
import {DmpListingModel} from "@app/core/model/dmp/dmp-listing";
import {DmpModel} from "@app/core/model/dmp/dmp";
import {GrantTabModel} from "@app/ui/dmp/editor/grant-tab/grant-tab-model";
import {ProjectFormModel} from "@app/ui/dmp/editor/grant-tab/project-form-model";
import {FunderFormModel} from "@app/ui/dmp/editor/grant-tab/funder-form-model";
import {ExtraPropertiesFormModel} from "@app/ui/dmp/editor/general-tab/extra-properties-form.model";
import {CloneDialogComponent} from "@app/ui/dmp/clone/clone-dialog/clone-dialog.component";
@Component({ @Component({
selector: 'app-drafts', selector: 'app-drafts',
@ -35,39 +50,43 @@ import { HttpClient } from '@angular/common/http';
}) })
export class DraftsComponent extends BaseComponent implements OnInit { export class DraftsComponent extends BaseComponent implements OnInit {
@Input() routerLink: string; @Output() totalCountRecentEdited: EventEmitter<any> = new EventEmitter();
@Output() totalCountDraftDatasets: EventEmitter<any> = new EventEmitter();
@ViewChild("drafts") resultsContainer;
datasetDrafts: DatasetListingModel[];
datasetDraftsTypeEnum = RecentActivityType;
status: number;
@ViewChild("results") resultsContainer;
allRecentActivities: RecentActivityModel[];
recentActivityTypeEnum = RecentActivityType;
dmpModel: DmpEditorModel;
isDraft: boolean;
totalCount: number; totalCount: number;
startIndex: number = 0; startIndex: number = 0;
pageSize: number = 5; dmpOffset: number = 0;
datasetOffset: number = 0;
offsetLess: number = 0; offsetLess: number = 0;
hasMoreResults:boolean = true; pageSize: number = 5;
dmpFormGroup: FormGroup;
hasMoreActivity:boolean = true;
public formGroup = new FormBuilder().group({ public formGroup = new FormBuilder().group({
like: new FormControl(), like: new FormControl(),
order: new FormControl() order: new FormControl()
}); });
publicMode = false;
order = RecentActivityOrder; order = RecentActivityOrder;
page: number = 1; page: number = 1;
@Input() isActive: boolean = false; @Input() isActive: boolean = false;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
private datasetService: DatasetService,
private authentication: AuthService,
private language: TranslateService,
public dialog: MatDialog,
private datasetWizardService: DatasetWizardService,
public enumUtils: EnumUtils, public enumUtils: EnumUtils,
private authentication: AuthService,
private dmpService: DmpService,
private dashboardService: DashboardService,
private language: TranslateService,
private dialog: MatDialog,
private uiNotificationService: UiNotificationService, private uiNotificationService: UiNotificationService,
private datasetWizardService: DatasetWizardService,
private location: Location, private location: Location,
private lockService: LockService, private lockService: LockService,
private httpClient: HttpClient, private httpClient: HttpClient,
@ -83,7 +102,8 @@ export class DraftsComponent extends BaseComponent implements OnInit {
let page = (params['page'] === undefined) ? 1 : +params['page']; let page = (params['page'] === undefined) ? 1 : +params['page'];
this.page = (page <= 0) ? 1 : page; this.page = (page <= 0) ? 1 : page;
this.startIndex = (this.page-1)*this.pageSize; this.datasetOffset = (this.page-1)*this.pageSize;
this.dmpOffset = (this.page-1)*this.pageSize;
if(this.page > 1) { if(this.page > 1) {
this.offsetLess = (this.page-2)*this.pageSize; this.offsetLess = (this.page-2)*this.pageSize;
} }
@ -94,48 +114,57 @@ export class DraftsComponent extends BaseComponent implements OnInit {
} }
this.formGroup.get('order').setValue(order); this.formGroup.get('order').setValue(order);
let keyword = (params['keyword'] === undefined || params['keyword'].length <= 0) ? "" : params['keyword']; let keyword = (params['keyword'] === undefined || params['keyword'].length <= 0) ? "" : params['keyword'];
this.formGroup.get("like").setValue(keyword); this.formGroup.get("like").setValue(keyword);
this.updateUrl(); this.updateUrl();
} }
// else {
// this.page = 1;
// this.formGroup.get('order').setValue(this.order.MODIFIED);
// this.formGroup.get("like").setValue("");
// }
}); });
// const fields: Array<string> = []; if (this.isAuthenticated()) {
// fields.push('-modified'); if (!this.formGroup.get('order').value) {
if(!this.formGroup.get('order').value) { this.formGroup.get('order').setValue(this.order.MODIFIED);
this.formGroup.get('order').setValue(this.order.MODIFIED);
}
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value];
const dmpDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(this.startIndex, 5, { fields: fields });
dmpDataTableRequest.criteria = new DatasetCriteria();
dmpDataTableRequest.criteria.like = this.formGroup.get('like').value;
dmpDataTableRequest.criteria.status = DmpStatus.Draft;
this.datasetService.getPaged(dmpDataTableRequest)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
this.datasetDrafts = response.data;
this.totalCount = response.totalCount;
this.totalCountDraftDatasets.emit(this.datasetDrafts.length);
if(this.totalCount > 0 && this.totalCount <= (this.page-1)*this.pageSize && this.page > 1) {
let queryParams = { type: "drafts", page: 1, order: this.formGroup.get("order").value };
if(this.formGroup.get("like").value) {
queryParams['keyword'] = this.formGroup.get("like").value;
}
this.router.navigate(["/home"], { queryParams: queryParams })
} }
}); const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value];
this.formGroup.get('like').valueChanges const allDataTableRequest: DataTableMultiTypeRequest<RecentActivityCriteria> = new DataTableMultiTypeRequest(this.dmpOffset, this.datasetOffset, 5, {fields: fields});
.pipe(takeUntil(this._destroyed), debounceTime(500)) allDataTableRequest.criteria = new RecentActivityCriteria();
.subscribe(x => this.refresh()); allDataTableRequest.criteria.like = this.formGroup.get('like').value;
this.formGroup.get('order').valueChanges allDataTableRequest.criteria.order = this.formGroup.get('order').value;
.pipe(takeUntil(this._destroyed)) allDataTableRequest.criteria.status = 0;
.subscribe(x => this.refresh());
this.dashboardService
.getRecentActivity(allDataTableRequest)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
this.allRecentActivities = response;
this.allRecentActivities.forEach(recentActivity => {
if (recentActivity.type === RecentActivityType.Dataset) {
// this.datasetOffset = this.datasetOffset + 1;
this.datasetOffset = this.page * this.pageSize;
} else if (recentActivity.type === RecentActivityType.Dmp) {
// this.dmpOffset = this.dmpOffset + 1;
this.dmpOffset = this.page * this.pageSize;
}
});
this.totalCountRecentEdited.emit(this.allRecentActivities.length);
if (this.allRecentActivities.length == 0 && this.page > 1) {
let queryParams = {type: "recent", page: 1, order: this.formGroup.get("order").value};
if (this.formGroup.get("like").value) {
queryParams['keyword'] = this.formGroup.get("like").value;
}
this.router.navigate(["/home"], {queryParams: queryParams})
}
});
this.formGroup.get('like').valueChanges
.pipe(takeUntil(this._destroyed), debounceTime(500))
.subscribe(x => {
this.refresh()
});
this.formGroup.get('order').valueChanges
.pipe(takeUntil(this._destroyed))
.subscribe(x => {
this.refresh()
});
}
} }
ngOnChanges() { ngOnChanges() {
@ -152,6 +181,178 @@ export class DraftsComponent extends BaseComponent implements OnInit {
this.location.go(this.router.url.split('?')[0]+parameters); this.location.go(this.router.url.split('?')[0]+parameters);
} }
getDatasets(activity: RecentDmpModel): DatasetUrlListing[] {
return activity.datasets;
}
getGroupId(activity: RecentDmpModel): string {
return activity.groupId;
}
getDmp(activity: RecentDatasetModel): String {
return activity.dmp;
}
getDmpId(activity: RecentDatasetModel): String {
return activity.dmpId;
}
public isAuthenticated(): boolean {
return !!this.authentication.current();
}
isUserOwner(activity: DmpListingModel): boolean {
const principal: Principal = this.authentication.current();
if (principal) return !!activity.users.find(x => (x.role === Role.Owner) && (principal.id === x.id));
}
editClicked(dmp: DmpListingModel) {
this.router.navigate(['/plans/edit/' + dmp.id]);
}
deleteDmpClicked(dmp: DmpListingModel) {
this.lockService.checkLockStatus(dmp.id).pipe(takeUntil(this._destroyed))
.subscribe(lockStatus => {
if (!lockStatus) {
this.openDeleteDmpDialog(dmp);
} else {
this.openDmpLockedByUserDialog();
}
});
}
cloneOrNewVersionClicked(dmp: RecentActivityModel, isNewVersion: boolean) {
this.dmpService.getSingle(dmp.id).pipe(map(data => data as DmpModel))
.pipe(takeUntil(this._destroyed))
.subscribe(data => {
this.dmpModel = new DmpEditorModel();
this.dmpModel.grant = new GrantTabModel();
this.dmpModel.project = new ProjectFormModel();
this.dmpModel.funder = new FunderFormModel();
this.dmpModel.extraProperties = new ExtraPropertiesFormModel();
this.dmpModel.fromModel(data);
this.dmpModel.status = DmpStatus.Draft;
this.dmpFormGroup = this.dmpModel.buildForm();
if (!isNewVersion) {
this.dmpFormGroup.get('label').setValue(dmp.title + " New");
}
this.openCloneDialog(isNewVersion);
});
}
openCloneDialog(isNewVersion: boolean) {
const dialogRef = this.dialog.open(CloneDialogComponent, {
maxWidth: '700px',
maxHeight: '80vh',
data: {
formGroup: this.dmpFormGroup,
datasets: this.dmpFormGroup.get('datasets').value,
isNewVersion: isNewVersion,
confirmButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.SAVE'),
cancelButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.CANCEL'),
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
if (!isNewVersion) {
this.dmpService.clone(this.dmpFormGroup.getRawValue(), this.dmpFormGroup.get('id').value)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCloneOrNewVersionCallbackSuccess(complete),
error => this.onCloneOrNewVersionCallbackError(error)
);
} else if (isNewVersion) {
this.dmpService.newVersion(this.dmpFormGroup.getRawValue(), this.dmpFormGroup.get('id').value)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onCloneOrNewVersionCallbackSuccess(complete),
error => this.onCloneOrNewVersionCallbackError(error)
);
}
}
});
}
openDeleteDmpDialog(dmp: DmpListingModel) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '300px',
restoreFocus: false,
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
isDeleteConfirmation: true
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.dmpService.delete(dmp.id)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onDeleteCallbackSuccess(),
error => this.onDeleteCallbackError(error)
);
}
});
}
openDmpLockedByUserDialog() {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '400px',
restoreFocus: false,
data: {
message: this.language.instant('DMP-EDITOR.ACTIONS.LOCK')
}
});
}
openShareDialog(rowId: any, rowName: any) {
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
// height: '250px',
// width: '700px',
autoFocus: false,
restoreFocus: false,
data: {
dmpId: rowId,
dmpName: rowName
}
});
}
isDraftDmp(activity: DmpListingModel) {
return activity.status == DmpStatus.Draft;
}
onCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/plans']);
}
reloadPage(): void {
const path = this.location.path();
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
this.router.navigate([path]);
});
}
onDeleteCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
this.reloadPage();
}
onDeleteCallbackError(error) {
this.uiNotificationService.snackBarNotification(error.error.message ? this.language.instant(error.error.message) : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
}
onCloneOrNewVersionCallbackSuccess(dmpId: String): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
this.router.navigate(['/plans/edit/', dmpId]);
}
onCloneOrNewVersionCallbackError(error: any) {
this.uiNotificationService.snackBarNotification(error.error.message ? this.language.instant(error.error.message) : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-CLONE'), SnackBarNotificationLevel.Error);
}
redirect(id: string, type: RecentActivityType) { redirect(id: string, type: RecentActivityType) {
switch (type) { switch (type) {
case RecentActivityType.Grant: { case RecentActivityType.Grant: {
@ -159,11 +360,15 @@ export class DraftsComponent extends BaseComponent implements OnInit {
return; return;
} }
case RecentActivityType.Dataset: { case RecentActivityType.Dataset: {
this.router.navigate(["datasets/edit/" + id]); if (this.isAuthenticated()) {
this.router.navigate(['../datasets/overview/' + id]);
}
return; return;
} }
case RecentActivityType.Dmp: { case RecentActivityType.Dmp: {
this.router.navigate(["plans/edit/" + id]); if (this.isAuthenticated()) {
this.router.navigate(['../plans/overview/' + id]);
}
return; return;
} }
default: default:
@ -171,13 +376,28 @@ export class DraftsComponent extends BaseComponent implements OnInit {
} }
} }
public isAuthenticated(): boolean { navigateToUrl(id: string, type: RecentActivityType): string[] {
return !!this.authentication.current(); switch (type) {
} case RecentActivityType.Grant: {
return ["grants/edit/" + id];
navigateToUrl() { }
if (!this.isAuthenticated()) { return; } case RecentActivityType.Dataset: {
this.router.navigate(['/datasets'], { queryParams: { status: 0 } }); if (this.isAuthenticated()) {
return ['../datasets/overview/' + id];
} else {
return ['../explore/publicOverview', id];
}
}
case RecentActivityType.Dmp: {
if (this.isAuthenticated()) {
return ['../plans/overview/' + id];
} else {
return ['../explore-plans/publicOverview', id];
}
}
default:
throw new Error("Unsupported Activity Type ");
}
} }
roleDisplay(value: any) { roleDisplay(value: any) {
@ -201,117 +421,68 @@ export class DraftsComponent extends BaseComponent implements OnInit {
} }
} }
openDmpSearchDialogue(dataset: DatasetListingModel) { // dmpProfileDisplay(value: any) {
const formControl = new FormControl(); // if (value != null) {
const dialogRef = this.dialog.open(DatasetCopyDialogueComponent, { // return value;
width: '500px', // }
restoreFocus: false, // else {
data: { // return "--";
formControl: formControl, // }
datasetId: dataset.id, // }
datasetProfileId: dataset.profile.id,
datasetProfileExist: false,
confirmButton: this.language.instant('DATASET-WIZARD.DIALOGUE.COPY'),
cancelButton: this.language.instant('DATASET-WIZARD.DIALOGUE.CANCEL')
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)) downloadXml(id: string) {
.subscribe(result => { this.dmpService.downloadXML(id)
if (result && result.datasetProfileExist) { .pipe(takeUntil(this._destroyed))
const newDmpId = result.formControl.value.id; .subscribe(response => {
this.router.navigate(['/datasets/copy/' + result.datasetId], { queryParams: { newDmpId: newDmpId } }); const blob = new Blob([response.body], { type: 'application/xml' });
// let url = this.router.createUrlTree(['/datasets/copy/', result.datasetId, { newDmpId: newDmpId } ]); const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
// window.open(url.toString(), '_blank');
} FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', "xml", id);
}); });
} }
deleteClicked(id: string) { downloadDocx(id: string) {
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed)) this.dmpService.downloadDocx(id)
.subscribe(lockStatus => { .pipe(takeUntil(this._destroyed))
if (!lockStatus) { .subscribe(response => {
this.openDeleteDialog(id); const blob = new Blob([response.body], { type: 'application/msword' });
} else { const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
this.openLockedByUserDialog();
} FileSaver.saveAs(blob, filename);
this.matomoService.trackDownload('dmps', "docx", id);
}); });
} }
openDeleteDialog(id: string): void { downloadPdf(id: string) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, { this.dmpService.downloadPDF(id)
maxWidth: '300px', .pipe(takeUntil(this._destroyed))
restoreFocus: false, .subscribe(response => {
data: { const blob = new Blob([response.body], { type: 'application/pdf' });
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'), FileSaver.saveAs(blob, filename);
isDeleteConfirmation: true this.matomoService.trackDownload('dmps', "pdf", id);
} });
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.datasetWizardService.delete(id)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onDeleteCallbackSuccess(),
error => this.onDeleteCallbackError(error)
);
}
});
} }
openLockedByUserDialog() { downloadJson(id: string) {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, { this.dmpService.downloadJson(id)
maxWidth: '400px', .pipe(takeUntil(this._destroyed))
restoreFocus: false, .subscribe(response => {
data: { const blob = new Blob([response.body], { type: 'application/json' });
message: this.language.instant('DATASET-WIZARD.ACTIONS.LOCK') const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
} FileSaver.saveAs(blob, filename);
}); this.matomoService.trackDownload('dmps', "json", id);
}, async error => {
this.onExportCallbackError(error);
});
} }
openShareDialog(dmpRowId: any, dmpRowName: any) { async onExportCallbackError(error: any) {
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, { const errorJsonText = await error.error.text();
// height: '250px', const errorObj = JSON.parse(errorJsonText);
// width: '700px', this.uiNotificationService.snackBarNotification(errorObj.message, SnackBarNotificationLevel.Error);
autoFocus: false,
restoreFocus: false,
data: {
dmpId: dmpRowId,
dmpName: dmpRowName
}
});
}
isUserOwner(activity: DatasetListingModel): boolean {
const principal: Principal = this.authentication.current();
if (principal) return !!activity.users.find(x => (x.role === Role.Owner) && (principal.id === x.id));
}
onCallbackSuccess(id?: String): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
id ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', id]); }) : this.router.navigate(['/datasets']);
}
onCallbackError(error: any) {
// this.setErrorModel(error.error);
}
reloadPage(): void {
const path = this.location.path();
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
this.router.navigate([path]);
});
}
onDeleteCallbackSuccess(): void {
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
this.reloadPage();
}
onDeleteCallbackError(error) {
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
} }
downloadPDF(dataset: DatasetListingModel): void { downloadPDF(dataset: DatasetListingModel): void {
@ -369,119 +540,177 @@ export class DraftsComponent extends BaseComponent implements OnInit {
return filename; return filename;
} }
refresh(): void { viewVersions(rowId: String, rowLabel: String, activity: DmpListingModel) {
this.page = 1; if (activity.public && !this.isUserOwner(activity)) {
this.updateUrl(); let url = this.router.createUrlTree(['/explore-plans/versions/', rowId, { groupLabel: rowLabel }]);
window.open(url.toString(), '_blank');
// this.router.navigate(['/explore-plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
} else {
let url = this.router.createUrlTree(['/plans/versions/', rowId, { groupLabel: rowLabel }]);
window.open(url.toString(), '_blank');
// this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
}
}
// const fields: Array<string> = []; openDmpSearchDialogue(dataset: RecentDatasetModel) {
// fields.push('-modified'); const formControl = new FormControl();
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value]; const dialogRef = this.dialog.open(DatasetCopyDialogueComponent, {
this.startIndex = 0; width: '500px',
const dmpDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 5, { fields: fields }); restoreFocus: false,
dmpDataTableRequest.criteria = new DatasetCriteria(); data: {
dmpDataTableRequest.criteria.status = DmpStatus.Draft; formControl: formControl,
dmpDataTableRequest.criteria.like = this.formGroup.get("like").value; datasetId: dataset.id,
this.datasetService.getPaged(dmpDataTableRequest) datasetProfileId: dataset.profile.id,
.pipe(takeUntil(this._destroyed)) datasetProfileExist: false,
.subscribe(response => { confirmButton: this.language.instant('DATASET-WIZARD.DIALOGUE.COPY'),
this.datasetDrafts = response.data; cancelButton: this.language.instant('DATASET-WIZARD.DIALOGUE.CANCEL')
this.totalCount = response.totalCount; }
this.totalCountDraftDatasets.emit(this.datasetDrafts.length); });
if(response.data.length< this.pageSize) {
this.hasMoreResults = false; dialogRef.afterClosed().pipe(takeUntil(this._destroyed))
} else { .subscribe(result => {
this.hasMoreResults = true; if (result && result.datasetProfileExist) {
const newDmpId = result.formControl.value.id;
// let url = this.router.createUrlTree(['/datasets/copy/', result.datasetId, { newDmpId: newDmpId }]);
// window.open(url.toString(), '_blank');
this.router.navigate(['/datasets/copy/' + result.datasetId], { queryParams: { newDmpId: newDmpId } });
}
});
}
deleteDatasetClicked(id: string) {
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed))
.subscribe(lockStatus => {
if (!lockStatus) {
this.openDeleteDatasetDialog(id);
} else {
this.openDatasetLockedByUserDialog();
}
});
}
openDeleteDatasetDialog(id: string): void {
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
maxWidth: '300px',
restoreFocus: false,
data: {
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
isDeleteConfirmation: true
}
});
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
if (result) {
this.datasetWizardService.delete(id)
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onDeleteCallbackSuccess(),
error => this.onDeleteCallbackError(error)
);
} }
}); });
} }
public loadNextOrPrevious(more: boolean = true) { openDatasetLockedByUserDialog() {
// const fields: Array<string> = ["-modified"]; const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value]; maxWidth: '400px',
let request; restoreFocus: false,
this.startIndex = (this.page)*this.pageSize; data: {
if(this.page > 1) { message: this.language.instant('DATASET-WIZARD.ACTIONS.LOCK')
this.offsetLess = (this.page-2)*this.pageSize; }
} });
if(more) { }
// this.startIndex = this.startIndex + this.pageSize;
request = new DataTableRequest<DatasetCriteria>(this.startIndex, this.pageSize, { fields: fields });
} else {
request = new DataTableRequest<DatasetCriteria>(this.offsetLess, this.pageSize, {fields: fields});
}
request.criteria = new DatasetCriteria();
request.criteria.status = DmpStatus.Draft;
request.criteria.like = this.formGroup.get("like").value;;
this.datasetService.getPaged(request).pipe(takeUntil(this._destroyed)).subscribe(result => { refresh(): void {
if (!result || !result.data || result.data.length == 0) { this.datasetOffset = 0;
this.hasMoreResults = false; this.dmpOffset = 0;
this.page = 1;
this.updateUrl();
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value];
// const fields: Array<string> = ["-modified"];
this.startIndex = 0;
const allDataTableRequest: DataTableMultiTypeRequest<RecentActivityCriteria> = new DataTableMultiTypeRequest(0, 0, this.pageSize, { fields: fields });
allDataTableRequest.criteria = new RecentActivityCriteria();
allDataTableRequest.criteria.like = this.formGroup.get("like").value;
allDataTableRequest.criteria.order = this.formGroup.get("order").value;
allDataTableRequest.criteria.status = 0;
this.dashboardService
.getRecentActivity(allDataTableRequest)
.pipe(takeUntil(this._destroyed))
.subscribe(response => {
this.allRecentActivities = response;
this.allRecentActivities.forEach(recentActivity => {
if (recentActivity.type === RecentActivityType.Dataset) {
// this.datasetOffset = this.datasetOffset + 1;
this.datasetOffset = this.page*this.pageSize;
} else if (recentActivity.type === RecentActivityType.Dmp) {
// this.dmpOffset = this.dmpOffset + 1;
this.dmpOffset = this.page*this.pageSize;
}
});
if(response.length< this.pageSize) {
this.hasMoreActivity = false;
} else {
this.hasMoreActivity = true;
}
this.totalCountRecentEdited.emit(this.allRecentActivities.length);
});
}
public loadNextOrPrevious(more: boolean = true) {
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value];
// const fields: Array<string> = ["-modified"];
let request;
if(more) {
request = new DataTableMultiTypeRequest<RecentActivityCriteria>(this.dmpOffset, this.datasetOffset, this.pageSize, {fields: fields});
} else {
request = new DataTableMultiTypeRequest<RecentActivityCriteria>(this.offsetLess, this.offsetLess, this.pageSize, {fields: fields});
}
request.criteria = new RecentActivityCriteria();
request.criteria.like = this.formGroup.get("like").value ? this.formGroup.get("like").value : "";
request.criteria.order = this.formGroup.get("order").value;
request.criteria.status = 0;
this.dashboardService.getRecentActivity(request).pipe(takeUntil(this._destroyed)).subscribe(result => {
if (!result || result.length == 0) {
this.hasMoreActivity = false;
// return []; // return [];
} else { } else {
// this.datasetDrafts = this.datasetDrafts.concat(result.data);
// this.datasetDrafts = this.datasetDrafts.length > 0 ? this.mergeTwoSortedLists(this.datasetDrafts, result.data, this.formGroup.get('order').value) : result.data;
this.page = this.page + (more ? 1 : -1); this.page = this.page + (more ? 1 : -1);
this.updateUrl(); this.updateUrl();
this.datasetDrafts = result.data; // if(more) {
if(result.data.length < this.pageSize) { // result.forEach(recentActivity => {
this.hasMoreResults = false; // if (recentActivity.type === RecentActivityType.Dataset) {
} else { // this.datasetOffset = this.datasetOffset + 1;
this.hasMoreResults = true; this.datasetOffset = this.page * this.pageSize;
// } else if (recentActivity.type === RecentActivityType.Dmp) {
// this.dmpOffset = this.dmpOffset + 1;
this.dmpOffset = this.page * this.pageSize;
// }
// });
// }
if (this.page > 1) {
this.offsetLess = (this.page - 2) * this.pageSize;
} }
this.totalCountDraftDatasets.emit(this.datasetDrafts.length);
if(result.length < this.pageSize) {
this.hasMoreActivity = false;
} else {
this.hasMoreActivity = true;
}
// this.allRecentActivities = this.allRecentActivities.concat(result);
// this.allRecentActivities = this.allRecentActivities.length > 0 ? this.mergeTwoSortedLists(this.allRecentActivities, result, this.formGroup.get('order').value) : result;
this.allRecentActivities = result;
this.totalCountRecentEdited.emit(this.allRecentActivities.length);
if (more) { if (more) {
this.resultsContainer.nativeElement.scrollIntoView(); this.resultsContainer.nativeElement.scrollIntoView();
} }
} }
}); });
} }
private mergeTwoSortedLists(arr1: DatasetListingModel[], arr2: DatasetListingModel[], order: string): DatasetListingModel[] {
let merged = [];
let index1 = 0;
let index2 = 0;
let current = 0;
while (current < (arr1.length + arr2.length)) {
let isArr1Depleted = index1 >= arr1.length;
let isArr2Depleted = index2 >= arr2.length;
if (order === 'modified') {
if (!isArr1Depleted && (isArr2Depleted || (new Date(arr1[index1].modified) > new Date(arr2[index2].modified)))) {
merged[current] = arr1[index1];
index1++;
} else {
merged[current] = arr2[index2];
index2++;
}
} else if (order === 'created') {
if (!isArr1Depleted && (isArr2Depleted || (new Date(arr1[index1].created) > new Date(arr2[index2].created)))) {
merged[current] = arr1[index1];
index1++;
} else {
merged[current] = arr2[index2];
index2++;
}
} else if (order === 'label') {
if (!isArr1Depleted && (isArr2Depleted || (arr1[index1].label < arr2[index2].label))) {
merged[current] = arr1[index1];
index1++;
} else {
merged[current] = arr2[index2];
index2++;
}
} else if (order === 'status') {
if (!isArr1Depleted && (isArr2Depleted || (arr1[index1].status < arr2[index2].status))) {
merged[current] = arr1[index1];
index1++;
} else {
merged[current] = arr2[index2];
index2++;
}
}
current++;
}
return merged;
}
} }

View File

@ -123,7 +123,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
let keyword = (params['keyword'] === undefined || params['keyword'].length <= 0) ? "" : params['keyword']; let keyword = (params['keyword'] === undefined || params['keyword'].length <= 0) ? "" : params['keyword'];
this.formGroup.get("like").setValue(keyword); this.formGroup.get("like").setValue(keyword);
console.log("init");
this.updateUrl(); this.updateUrl();
} }
}); });
@ -157,20 +156,17 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
if(this.formGroup.get("like").value) { if(this.formGroup.get("like").value) {
queryParams['keyword'] = this.formGroup.get("like").value; queryParams['keyword'] = this.formGroup.get("like").value;
} }
console.log(queryParams);
this.router.navigate(["/home"], { queryParams: queryParams }) this.router.navigate(["/home"], { queryParams: queryParams })
} }
}); });
this.formGroup.get('like').valueChanges this.formGroup.get('like').valueChanges
.pipe(takeUntil(this._destroyed), debounceTime(500)) .pipe(takeUntil(this._destroyed), debounceTime(500))
.subscribe(x => { .subscribe(x => {
console.log("like changed");
this.refresh() this.refresh()
}); });
this.formGroup.get('order').valueChanges this.formGroup.get('order').valueChanges
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(x => { .subscribe(x => {
console.log("order changed");
this.refresh() this.refresh()
}); });
} else { } else {
@ -199,20 +195,17 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
if(this.formGroup.get("like").value) { if(this.formGroup.get("like").value) {
queryParams['keyword'] = this.formGroup.get("like").value; queryParams['keyword'] = this.formGroup.get("like").value;
} }
console.log(queryParams);
this.router.navigate(["/home"], { queryParams: queryParams }) this.router.navigate(["/home"], { queryParams: queryParams })
} }
}); });
this.formGroup.get('like').valueChanges this.formGroup.get('like').valueChanges
.pipe(takeUntil(this._destroyed), debounceTime(500)) .pipe(takeUntil(this._destroyed), debounceTime(500))
.subscribe(x => { .subscribe(x => {
console.log("like changed 1");
this.refresh() this.refresh()
}); });
this.formGroup.get('order').valueChanges this.formGroup.get('order').valueChanges
.pipe(takeUntil(this._destroyed)) .pipe(takeUntil(this._destroyed))
.subscribe(x => { .subscribe(x => {
console.log("order changed 1");
this.refresh() this.refresh()
}); });
} }
@ -220,7 +213,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
ngOnChanges() { ngOnChanges() {
if(this.isActive) { if(this.isActive) {
console.log("active");
this.updateUrl(); this.updateUrl();
} }
} }
@ -233,7 +225,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
if(parameters) { if(parameters) {
parameters = "?type=recent" + parameters; parameters = "?type=recent" + parameters;
} }
console.log(parameters);
this.location.go(this.router.url.split('?')[0]+parameters); this.location.go(this.router.url.split('?')[0]+parameters);
} }
@ -710,7 +701,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
this.datasetOffset = 0; this.datasetOffset = 0;
this.dmpOffset = 0; this.dmpOffset = 0;
this.page = 1; this.page = 1;
console.log("refresh");
this.updateUrl(); this.updateUrl();
const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value]; const fields: Array<string> = [((this.formGroup.get('order').value === 'status') || (this.formGroup.get('order').value === 'label') ? '+' : "-") + this.formGroup.get('order').value];
@ -763,7 +753,6 @@ export class RecentEditedActivityComponent extends BaseComponent implements OnIn
// return []; // return [];
} else { } else {
this.page = this.page + (more ? 1 : -1); this.page = this.page + (more ? 1 : -1);
console.log("loadNextOrPrevious");
this.updateUrl(); this.updateUrl();
// if(more) { // if(more) {
// result.forEach(recentActivity => { // result.forEach(recentActivity => {