Skip to content

Commit

Permalink
[DSC-1514] Changed "cancel" button in Metadata registry & Bulk Access…
Browse files Browse the repository at this point in the history
… Management
  • Loading branch information
alisaismailati committed May 16, 2024
1 parent cebe77d commit 6c6cdb8
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 69 deletions.
8 changes: 4 additions & 4 deletions src/app/access-control/bulk-access/bulk-access.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<hr>

<div class="d-flex justify-content-end">
<button class="btn btn-outline-primary mr-3" (click)="reset()">
<i class="fas fa-times mr-1"></i>
{{ 'access-control-cancel' | translate }}
</button>
<a routerLink="/home" class="btn btn-outline-primary mr-3">
<i class="fas fa-arrow-left mr-1"></i>
{{ 'access-control-back' | translate }}
</a>
<button class="btn btn-primary" [disabled]="!canExport()" (click)="submit()">
<i class="fas fa-cogs mr-1"></i>
{{ 'access-control-execute' | translate }}
Expand Down
12 changes: 7 additions & 5 deletions src/app/access-control/bulk-access/bulk-access.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Process } from '../../process-page/processes/process.model';
import { RouterTestingModule } from '@angular/router/testing';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { NotificationsServiceStub } from '../../shared/testing/notifications-service.stub';
import { By } from '@angular/platform-browser';

describe('BulkAccessComponent', () => {
let component: BulkAccessComponent;
Expand Down Expand Up @@ -141,11 +142,6 @@ describe('BulkAccessComponent', () => {
expect(component.canExport()).toBe(true);
});

it('should call the settings reset method when reset is called', () => {
component.reset();
expect(component.settings.reset).toHaveBeenCalled();
});

it('should call the bulkAccessControlService executeScript method when submit is called', () => {
(component.settings as any).getValue.and.returnValue(mockFormState);
bulkAccessControlService.createPayloadFile.and.returnValue(mockFile);
Expand All @@ -154,5 +150,11 @@ describe('BulkAccessComponent', () => {
component.submit();
expect(bulkAccessControlService.executeScript).toHaveBeenCalled();
});

it('should have a link to /home', () => {
const link = fixture.debugElement.query(By.css('a.btn-outline-primary'));
expect(link).toBeTruthy();
expect(link.properties.href).toContain('/home');
});
});
});
8 changes: 0 additions & 8 deletions src/app/access-control/bulk-access/bulk-access.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ export class BulkAccessComponent implements OnInit {
return this.objectsSelected$.value?.length > 0;
}

/**
* Reset the form to its initial state
* This will also reset the state of the child components (bitstream and item access)
*/
reset(): void {
this.settings.reset();
}

/**
* Submit the form
* This will create a payload file and execute the script
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('BulkAccessSettingsComponent', () => {

const mockControl: any = jasmine.createSpyObj('AccessControlFormContainerComponent', {
getFormValue: jasmine.createSpy('getFormValue'),
reset: jasmine.createSpy('reset')
});

beforeEach(async () => {
Expand All @@ -62,20 +61,11 @@ describe('BulkAccessSettingsComponent', () => {
expect(component.getValue).toBeDefined();
});

it('should have a method to reset the form', () => {
expect(component.reset).toBeDefined();
});

it('should return the correct form value', () => {
const expectedValue = mockFormState;
(component.controlForm as any).getFormValue.and.returnValue(mockFormState);
const actualValue = component.getValue();
// @ts-ignore
expect(actualValue).toEqual(expectedValue);
});

it('should call reset on the control form', () => {
component.reset();
expect(component.controlForm.reset).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,4 @@ export class BulkAccessSettingsComponent {
getValue() {
return this.controlForm.getFormValue();
}

/**
* Reset the form to its initial state
* This will also reset the state of the child components (bitstream and item access)
*/
reset() {
this.controlForm.reset();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h2 class="border-bottom pb-2">{{messagePrefix + '.edit' | translate}}</h2>
[formModel]="formModel"
[formGroup]="formGroup"
[formLayout]="formLayout"
[displayCancel]="false"
[displayReset]="false"
[submitLabel]="submitLabel"
(submitForm)="onSubmit()">
<div before class="btn-group">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2 class="border-bottom pb-2">
[formModel]="formModel"
[formGroup]="formGroup"
[formLayout]="formLayout"
[displayCancel]="false"
[displayReset]="false"
(submitForm)="onSubmit()">
<div before class="btn-group">
<button (click)="onCancel()" type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h4 *ngIf="contentSource && (contentSource?.harvestType !== harvestTypeNone)">{{
[formModel]="formModel"
[formLayout]="formLayout"
[displaySubmit]="false"
[displayCancel]="false"
[displayReset]="false"
(dfChange)="onChange($event)"
(submitForm)="onSubmit()"
(cancel)="onCancel()"></ds-form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
[formModel]="formModel"
[formGroup]="formGroup"
[displaySubmit]="false"
[displayCancel]="false">
[displayReset]="false">
</ds-form>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[formModel]="formModel"
[formGroup]="formGroup"
[displaySubmit]="false"
[displayCancel]="false">
[displayReset]="false">
</ds-form>
<div id="notSame" class="container-fluid text-danger" *ngIf="formGroup.hasError('notSame')">{{FORM_PREFIX + 'error.matching-passwords' | translate}}</div>
<div id="emptyPassword" class="container-fluid text-danger" *ngIf="(formGroup.dirty || formGroup.touched) && formGroup.hasError('emptyPassword')">{{FORM_PREFIX + 'error.empty-password' | translate}}</div>
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ <h5 class="mt-3">{{'access-control-access-conditions' | translate}}</h5>
</div>
</div>

<hr *ngIf="showSubmit">
<hr>

<div *ngIf="showSubmit" class="d-flex justify-content-end">
<button class="btn btn-outline-primary mr-3" (click)="reset()" type="button">
{{ 'access-control-cancel' | translate }}
<div class="d-flex justify-content-end">
<button class="btn btn-outline-primary" (click)="reset()" type="button">
<i class="fas fa-undo-alt mr-1"></i>
{{ 'access-control-reset' | translate }}
</button>
<button class="btn btn-primary"
<button class="btn btn-primary ml-3"
*ngIf="showSubmit"
[disabled]="!state.item.toggleStatus && !state.bitstream.toggleStatus"
(click)="submit()" type="submit">
<i class="fas fa-cogs mr-1"></i>
{{ 'access-control-execute' | translate }}
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ds-form *ngIf="formModel"
[formId]="'comcol-form-id'"
[formModel]="formModel"
[displayCancel]="false"
[displayReset]="false"
(submitForm)="onSubmit()">
<button (click)="back.emit()" before class="btn btn-outline-secondary" type="button">
<i class="fas fa-arrow-left"></i> {{ type.value + '.edit.return' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h5 class="modal-title">{{ getHeader() }}</h5>
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="false"
[displayCancel]="false"
[displayReset]="false"
[emitChange]="false"
(dfBlur)="onBlur($event)"
(ngbEvent)="changeSecurity($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ds-form #formRef="formComponent" *ngIf="formModel" @shrinkInOut
[formId]="formId"
[formModel]="formModel"
[displayCancel]="false"
[displayReset]="false"
[displaySubmit]="false"
[arrayButtonsStyle]="'inline-btn-group'"
[isInlineGroupForm]="true"
Expand Down
10 changes: 5 additions & 5 deletions src/app/shared/form/form.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@

</ds-dynamic-form>
<ng-content select="[additional]"></ng-content>
<ng-content *ngIf="!displaySubmit && !displayCancel"></ng-content>
<ng-content *ngIf="!displaySubmit && !displayReset"></ng-content>

<div *ngIf="displaySubmit || displayCancel">
<div *ngIf="displaySubmit || displayReset">
<hr>
<div class="form-group row">
<div class="col text-right space-children-mr">
<ng-content select="[before]"></ng-content>
<button *ngIf="displayCancel" type="reset" class="btn btn-outline-secondary" (click)="reset()">
<i class="fa fa-times"></i> {{cancelLabel | translate}}
<button *ngIf="displayReset" type="reset" class="btn btn-outline-secondary" (click)="reset()">
<i class="fas fa-undo-alt mr-1"></i>{{resetLabel | translate}}
</button>
<ng-content select="[between]"></ng-content>
<button *ngIf="displaySubmit" type="submit" class="btn btn-primary" (click)="onSubmit()"
[disabled]="!(isValid() | async)"><i class="fas fa-save"></i> {{submitLabel | translate}}
[disabled]="!(isValid() | async)"><i class="fas fa-save mr-1"></i> {{submitLabel | translate}}
</button>
<ng-content select="[after]"></ng-content>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/app/shared/form/form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('FormComponent test suite', () => {
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="displaySubmit"
[displayCancel]="displayCancel"></ds-form>`;
[displayReset]="displayCancel"></ds-form>`;

testFixture = createTestComponent(html, TestComponent) as ComponentFixture<TestComponent>;
testComp = testFixture.componentInstance;
Expand All @@ -205,7 +205,7 @@ describe('FormComponent test suite', () => {
formComp.formId = 'testForm';
formComp.formModel = TEST_FORM_MODEL;
formComp.displaySubmit = false;
formComp.displayCancel = false;
formComp.displayReset = false;
form = new BehaviorSubject(formState);
valid = new BehaviorSubject(false);
spyOn((formComp as any).formService, 'getForm').and.returnValue(form);
Expand Down Expand Up @@ -405,7 +405,7 @@ describe('FormComponent test suite', () => {
formComp.formId = 'testFormArray';
formComp.formModel = TEST_FORM_MODEL_WITH_ARRAY;
formComp.displaySubmit = false;
formComp.displayCancel = false;
formComp.displayReset = false;
formFixture.detectChanges();
spyOn(store, 'dispatch');
});
Expand Down Expand Up @@ -460,7 +460,7 @@ describe('FormComponent test suite', () => {
formComp.formId = 'testFormArray';
formComp.formModel = TEST_FORM_MODEL_WITH_ARRAY;
formComp.displaySubmit = false;
formComp.displayCancel = false;
formComp.displayReset = false;
formFixture.detectChanges();
spyOn(store, 'dispatch');
});
Expand Down Expand Up @@ -563,7 +563,7 @@ describe('FormComponent test suite', () => {
formComp.formId = 'testFormArray';
formComp.formModel = TEST_FORM_MODEL_WITH_ARRAY;
formComp.displaySubmit = false;
formComp.displayCancel = false;
formComp.displayReset = false;
formFixture.detectChanges();
spyOn(store, 'dispatch');
});
Expand Down
8 changes: 4 additions & 4 deletions src/app/shared/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export class FormComponent implements OnDestroy, OnInit {
@Input() displaySubmit = true;

/**
* A boolean that indicate if to display form's cancel button
* A boolean that indicate if to display form's reset button
*/
@Input() displayCancel = true;
@Input() displayReset = true;

/**
* A String that indicate the entity type of the item
Expand All @@ -78,9 +78,9 @@ export class FormComponent implements OnDestroy, OnInit {
@Input() submitLabel = 'form.submit';

/**
* i18n key for the cancel button
* i18n key for the reset button
*/
@Input() cancelLabel = 'form.cancel';
@Input() resetLabel = 'form.reset';

/**
* An array of DynamicFormControlModel type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="false"
[displayCancel]="false"></ds-form>
[displayReset]="false"></ds-form>
<div class="container-fluid">
<label for="ResourcePolicyObject">{{'resource-policies.form.eperson-group-list.label' | translate}}</label>
<input id="ResourcePolicyObject" class="form-control mb-3" type="text" [value]="resourcePolicyTargetName$ | async">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="false"
[displayCancel]="false"
[displayReset]="false"
(dfChange)="onChange($event)"
(removeArrayItem)="onRemove($event)"></ds-form>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div class="custom-url" style="display: flex;align-items: center;">
<span class="frontend-url"> {{frontendUrl}}/</span>
<ds-form *ngIf="formModel" #formRef="formComponent" [formId]="formId" [formModel]="formModel" [displaySubmit]="false" [displayCancel]="false"
<ds-form *ngIf="formModel" #formRef="formComponent" [formId]="formId" [formModel]="formModel" [displaySubmit]="false" [displayReset]="false"
(dfChange)="onChange($event)"></ds-form>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="false"
[displayCancel]="false"
[displayReset]="false"
[entityType]="entityType"
(dfChange)="onChange($event)"
(dfFocus)="onFocus($event)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
[formModel]="formModel"
[formLayout]="formLayout"
[displaySubmit]="displaySubmit"
[displayCancel]="false"
[displayReset]="false"
(dfChange)="onChange($event)"></ds-form>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h4 class="modal-title">{{'submission.sections.upload.edit.title' | translate}}<
[formId]="formId"
[formModel]="formModel"
[displaySubmit]="!isSaving"
[displayCancel]="!isSaving"
[displayReset]="!isSaving"
(submitForm)="onSubmit()"
(cancel)="onModalClose()"
(dfChange)="onChange($event)"></ds-form>
Expand Down
6 changes: 6 additions & 0 deletions src/assets/i18n/en.json5
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,8 @@

"form.cancel": "Cancel",

"form.reset": "Reset",

"form.clear": "Clear",

"form.clear-help": "Click here to remove the selected value",
Expand Down Expand Up @@ -7290,6 +7292,10 @@

"access-control-cancel": "Cancel",

"access-control-reset": "Reset",

"access-control-back": "Back",

"access-control-execute": "Execute",

"access-control-add-more": "Add more",
Expand Down

0 comments on commit 6c6cdb8

Please sign in to comment.