-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/729 refactor settings releases (#733)
* refactor: settings release component
- Loading branch information
Showing
45 changed files
with
1,267 additions
and
514 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BaseService } from '../base/base.service'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { filter, Observable, Subject } from 'rxjs'; | ||
import { catchError, map } from 'rxjs/operators'; | ||
import { Restriction } from '../settings/permission/restriction'; | ||
import { Release } from '../settings/releases/release'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class AuthService extends BaseService { | ||
private readonly _cachedUserRestrictions: Subject<Restriction[]>; | ||
private readonly _userData: Observable<Restriction[]>; | ||
|
||
constructor(private http: HttpClient) { | ||
super(); | ||
if (!this._cachedUserRestrictions) { | ||
this._cachedUserRestrictions = new Subject<Restriction[]>(); | ||
this.refreshData(); | ||
} | ||
this._userData = this._cachedUserRestrictions.asObservable(); | ||
} | ||
|
||
private refreshData() { | ||
this.getRestrictions().subscribe({ | ||
next: (r) => this._cachedUserRestrictions.next(r), | ||
error: (e) => console.log(e), | ||
}); | ||
} | ||
|
||
private getRestrictions(): Observable<Restriction[]> { | ||
return this.http | ||
.get<Restriction[]>(`${this.getBaseUrl()}/permissions/restrictions/ownRestrictions/`, { | ||
headers: this.getHeaders(), | ||
}) | ||
.pipe(catchError(this.handleError)); | ||
} | ||
|
||
get userRestrictions() { | ||
return this._userData; | ||
} | ||
|
||
getActionsForPermission(permissionName: string) { | ||
return this._userData.pipe( | ||
map((restrictions) => { | ||
return restrictions.filter((entry) => entry.permission.name === permissionName).map((entry) => entry.action); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Restriction { | ||
role: string; | ||
permission: string; | ||
resourceType: string; | ||
resourceTypePermission: string; | ||
context: number; | ||
action: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const AMW_LOGOUT_URL = 'amw.logoutUrl'; | ||
// used for date-fns | ||
export const DATE_FORMAT = 'dd.MM.yyyy HH:mm'; | ||
export const DATE_TIME_FORMAT = 'dd.MM.yyyy HH:mm'; | ||
export const DATE_FORMAT = 'dd.MM.yyyy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
AMW_angular/io/src/app/settings/releases/release-delete.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="deleteReleaseTitle">{{ getTitle() }}</h5> | ||
<button type="button" class="btn btn-light close" aria-label="Close" (click)="cancel()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="form-horizontal mx-2"> | ||
<div class="mb-3"> | ||
@if (!hasResources) { | ||
<div class="text-body">Do you really want to delete the release {{ release.name }} ?</div> | ||
} @else { | ||
<div class="text-body"> | ||
The release {{ release.name }} is used by the following resources and can not be deleted: | ||
<ul class="list-group mt-2"> | ||
@for (item of resources | keyvalue; track item) { | ||
<li class="list-group-item"> | ||
<div class="d-flex justify-content-between align-items-start"> | ||
{{ item.key }} <span class="badge bg-primary rounded-pill ms-auto">{{ item.value.length }}</span> | ||
</div> | ||
<ul class="list-unstyled"> | ||
@for (rs of item.value; track rs) { | ||
<li> | ||
<small class="bi-dot">{{ rs.name }}</small> | ||
</li> | ||
} | ||
</ul> | ||
</li> | ||
} | ||
</ul> | ||
</div> | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-light" (click)="cancel()">Cancel</button> | ||
<button type="button" class="btn btn-primary" [disabled]="hasResources" (click)="delete()">Delete</button> | ||
</div> |
16 changes: 16 additions & 0 deletions
16
AMW_angular/io/src/app/settings/releases/release-delete.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { ReleaseDeleteComponent } from './release-delete.component'; | ||
|
||
describe('ReleaseDeleteComponent', () => { | ||
let component: ReleaseDeleteComponent; | ||
const activeModal = new NgbActiveModal(); | ||
|
||
beforeEach(async () => { | ||
component = new ReleaseDeleteComponent(activeModal); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
AMW_angular/io/src/app/settings/releases/release-delete.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { Release } from './release'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { AsyncPipe, KeyValuePipe, NgFor, NgForOf, NgIf } from '@angular/common'; | ||
import { ResourceEntity } from './resourceEntity'; | ||
|
||
@Component({ | ||
selector: 'amw-release-delete', | ||
standalone: true, | ||
imports: [AsyncPipe, KeyValuePipe, NgIf, NgFor, NgForOf, FormsModule], | ||
templateUrl: './release-delete.component.html', | ||
}) | ||
export class ReleaseDeleteComponent implements OnInit { | ||
@Input() release: Release; | ||
@Input() resources: Map<string, ResourceEntity[]>; | ||
@Output() deleteRelease: EventEmitter<Release> = new EventEmitter<Release>(); | ||
|
||
hasResources: boolean = false; | ||
|
||
constructor(public activeModal: NgbActiveModal) { | ||
this.activeModal = activeModal; | ||
} | ||
|
||
ngOnInit(): void { | ||
if (this.resources.size > 0) { | ||
this.hasResources = true; | ||
} | ||
} | ||
|
||
getTitle(): string { | ||
return 'Remove release'; | ||
} | ||
|
||
cancel() { | ||
this.activeModal.close(); | ||
} | ||
|
||
delete() { | ||
this.deleteRelease.emit(this.release); | ||
this.activeModal.close(); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
AMW_angular/io/src/app/settings/releases/release-edit.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="editReleaseTitle">{{ getTitle() }}</h5> | ||
<button type="button" class="btn btn-light close" aria-label="Close" (click)="cancel()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="form-horizontal mx-2"> | ||
<div class="mb-3"> | ||
<label for="name" class="form-label">Release name</label> | ||
<input type="text" class="form-control" id="name" [(ngModel)]="release.name" /> | ||
</div> | ||
<div class="mb-3"> | ||
<div class="form-check"> | ||
<label for="main" class="form-check-label">Main release</label> | ||
<input type="checkbox" class="form-check-input" id="main" [(ngModel)]="release.mainRelease" /> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="releaseDate" class="form-label">Installation date</label> | ||
<div id="releaseDate" class="form-text input-group date mb-3" required> | ||
<app-date-picker | ||
[(ngModel)]="installationDate" | ||
[dateStringFormat]="dateFormat" | ||
name="installationDate" | ||
id="datetimepicker" | ||
class="w-100" | ||
></app-date-picker> | ||
</div> | ||
@if (hasInvalidDate()) { | ||
<div class="text-warning">The installation date is mandatory</div> | ||
} | ||
</div> | ||
<div class="mb-3"> | ||
<label for="description" class="form-label">Release description</label> | ||
<textarea type="text" class="form-control" id="description" [(ngModel)]="release.description"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="button" class="btn btn-light" (click)="cancel()">Cancel</button> | ||
<button type="button" class="btn btn-primary" [disabled]="hasInvalidDate()" (click)="save()">Save changes</button> | ||
</div> |
15 changes: 15 additions & 0 deletions
15
AMW_angular/io/src/app/settings/releases/release-edit.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ReleaseEditComponent } from './release-edit.component'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
describe('ReleasesEditComponent', () => { | ||
let component: ReleaseEditComponent; | ||
const activeModal = new NgbActiveModal(); | ||
|
||
beforeEach(async () => { | ||
component = new ReleaseEditComponent(activeModal); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
60 changes: 60 additions & 0 deletions
60
AMW_angular/io/src/app/settings/releases/release-edit.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { Release } from './release'; | ||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { DatePickerComponent } from '../../shared/date-picker/date-picker.component'; | ||
import { DATE_FORMAT } from '../../core/amw-constants'; | ||
import { DateModel } from '../../shared/date-picker/date.model'; | ||
import { NgIf } from '@angular/common'; | ||
|
||
@Component({ | ||
selector: 'amw-release-edit', | ||
templateUrl: './release-edit.component.html', | ||
standalone: true, | ||
imports: [DatePickerComponent, NgIf, FormsModule], | ||
}) | ||
export class ReleaseEditComponent implements OnInit { | ||
@Input() release: Release; | ||
@Output() saveRelease: EventEmitter<Release> = new EventEmitter<Release>(); | ||
|
||
dateFormat = DATE_FORMAT; | ||
installationDate: DateModel = null; | ||
|
||
constructor(public activeModal: NgbActiveModal) { | ||
this.activeModal = activeModal; | ||
} | ||
|
||
ngOnInit(): void { | ||
if (this.release) { | ||
this.installationDate = DateModel.fromEpoch(this.release.installationInProductionAt); | ||
} | ||
} | ||
|
||
getTitle(): string { | ||
return this.release.id ? 'Edit release' : 'Add release'; | ||
} | ||
|
||
hasInvalidDate(): boolean { | ||
return this.installationDate == null || this.installationDate.toEpoch() == null; | ||
} | ||
|
||
cancel() { | ||
this.activeModal.close(); | ||
} | ||
|
||
save() { | ||
if (this.installationDate.toEpoch() != null) { | ||
const release: Release = { | ||
name: this.release.name, | ||
mainRelease: this.release.mainRelease, | ||
description: this.release.description, | ||
installationInProductionAt: this.installationDate.toEpoch(), | ||
id: this.release.id ? this.release.id : null, | ||
default: false, | ||
v: this.release.v ? this.release.v : null, | ||
}; | ||
this.saveRelease.emit(release); | ||
this.activeModal.close(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface Release { | ||
name: string; | ||
mainRelease: boolean; | ||
description: string; | ||
installationInProductionAt: number; | ||
id: number; | ||
v: number; | ||
default: boolean; | ||
} |
Oops, something went wrong.