Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surveys: archive individual survey (fixes #6620) #7807

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ export class DashboardNotificationsDialogComponent implements OnInit {
}));
this.surveysCount = this.surveys.length;
}

}
4 changes: 3 additions & 1 deletion src/app/login/login-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ export class LoginFormComponent {
const adminName = configuration.adminName.split('@')[0];
return isCreate ? this.sendNotifications(adminName, name) : of(sessionData);
}),
switchMap(() => this.submissionsService.getSubmissions(findDocuments({ type: 'survey', status: 'pending', 'user.name': name }))),
switchMap(() => this.submissionsService.getSubmissions(findDocuments({
type: 'survey', status: 'pending', 'user.name': name
}))),
map((surveys) => {
const uniqueSurveys = dedupeObjectArray(surveys, [ 'parentId' ]);
if (uniqueSurveys.length > 0) {
Expand Down
29 changes: 25 additions & 4 deletions src/app/surveys/surveys.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,28 @@
<mat-header-cell *matHeaderCellDef i18n>Action</mat-header-cell>
<mat-cell *matCellDef="let element">
<ng-container *ngIf="!element.parent === true">
<button mat-raised-button color="primary" (click)="routeToEditSurvey('update', element._id)" i18n><mat-icon>edit</mat-icon> Edit</button>
<button mat-raised-button color="primary" [disabled]="!element.questions.length" (click)="openSendSurveyDialog(element)" i18n><mat-icon>send</mat-icon> Send</button>
<button mat-raised-button color="primary" [disabled]="!element.questions.length" (click)="recordSurvey(element)"
i18n-matTooltip matTooltip="Record survey information from a person who is not a member of {{configuration.name}}" i18n>
<button
mat-raised-button color="primary"
[disabled]= "element.isArchived"
(click)="routeToEditSurvey('update', element._id)"
i18n-matTooltip matTooltip="Survey is archived and cannot be edit"
i18n>
<mat-icon>edit</mat-icon> Edit
</button>
<button
mat-raised-button color="primary"
[disabled]="!element.questions.length || element.isArchived"
(click)="openSendSurveyDialog(element)"
i18n-matTooltip matTooltip="element.isArchived ? 'Survey is archived and cannot be sent' : 'No questions inside survey'"
i18n>
<mat-icon>send</mat-icon> Send
</button>
<button
mat-raised-button color="primary"
[disabled]="!element.questions.length || element.isArchived"
(click)="recordSurvey(element)"
i18n-matTooltip matTooltip="Record survey information from a person who is not a member of {{configuration.name}}"
i18n>
<mat-icon>fiber_manual_record</mat-icon> Record
</button>
</ng-container>
Expand All @@ -77,6 +95,9 @@
<button mat-menu-item (click)="exportPdf(element)" i18n>Print (PDF)</button>
</mat-menu>
</div>
<ng-container *ngIf="!element.parent === true && !element.course">
<button mat-raised-button color="primary" (click)="archiveSurvey(element)" [disabled]="element.isArchived" i18n><mat-icon>archive</mat-icon> Archive</button>
</ng-container>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
Expand Down
35 changes: 33 additions & 2 deletions src/app/surveys/surveys.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { MatPaginator, PageEvent } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { forkJoin, Subject } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { forkJoin, Subject, throwError } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
import { CouchService } from '../shared/couchdb.service';
import {
filterSpecificFields, sortNumberOrString, createDeleteArray, selectedOutOfFilter
Expand Down Expand Up @@ -283,4 +283,35 @@ export class SurveysComponent implements OnInit, AfterViewInit, OnDestroy {
);
}

archiveSurvey(survey) {
const updatedSurvey = {
...survey,
isArchived: true,
};

return this.couchService.updateDocument(this.dbName, updatedSurvey).pipe(
switchMap(() => {
this.planetMessageService.showMessage($localize`Survey archived: ${survey.name}`);
this.surveys.data = this.surveys.data.map((s) =>
s._id === survey._id ? { ...s, isArchived: true } : s
);

const submissionRequests = this.submissionDeleteReq([], survey).map((req) =>
req.pipe(
catchError((err) => throwError(err))
)
);

return forkJoin(submissionRequests);
}),
catchError((err) => {
this.planetMessageService.showAlert($localize`There was a problem archiving this survey or deleting submissions.`);
return throwError(err);
})
).subscribe({
next: () => {},
error: () => {},
});

}
}
Loading