-
Notifications
You must be signed in to change notification settings - Fork 6
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
Feature/IOT-1583: Move application #167
Changes from 6 commits
6b6e6a2
d8fc16d
bebebec
8070bf9
f8a8d3e
392a1c7
2f3c8f9
617dcd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<div class="application-change-organization-dialog"> | ||
<h1 mat-dialog-title>{{ "APPLICATION.CHANGE-ORGANIZATION.TITLE" | translate }}</h1> | ||
<div mat-dialog-content> | ||
<label class="form-label" for="userGroup">{{ | ||
"APPLICATION.CHANGE-ORGANIZATION.CHOOSE-ORGANIZATION" | translate | ||
}}</label> | ||
<mat-select | ||
id="userGroup" | ||
class="form-control" | ||
panelClass="overflow-x-hidden" | ||
[(value)]="application.organizationId" | ||
[compareWith]="compare" | ||
(selectionChange)="onOrganizationChange()" | ||
> | ||
<mat-option *ngFor="let organization of filteredOrganizations | async" [value]="organization.id"> | ||
{{ organization.name }} | ||
</mat-option> | ||
</mat-select> | ||
<label class="form-label" for="userGroup">{{ | ||
"APPLICATION.CHANGE-ORGANIZATION.CHOOSE-USER-GROUPS" | translate | ||
}}</label> | ||
<mat-select | ||
id="userGroup" | ||
class="form-control" | ||
[multiple]="true" | ||
panelClass="overflow-x-hidden" | ||
[(value)]="application.permissionIds" | ||
[compareWith]="compare" | ||
> | ||
<mat-option *ngFor="let permission of filteredPermissionsMulti | async" [value]="permission.id"> | ||
{{ permission.name }} | ||
</mat-option> | ||
</mat-select> | ||
<mat-hint>{{ "APPLICATION.CHANGE-ORGANIZATION.USER-GROUP-AUTO-SELECT" | translate }}</mat-hint> | ||
</div> | ||
<div mat-dialog-actions class="d-flex flex-row"> | ||
<button (click)="onSubmit()" class="btn btn-primary"> | ||
{{ "GEN.SAVE" | translate }} | ||
</button> | ||
<button mat-dialog-close [mat-dialog-close]="false" class="btn btn-secondary ml-2"> | ||
{{ "GEN.CANCEL" | translate }} | ||
</button> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.application-change-organization-dialog { | ||
width: 50vw; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { Component, Inject, OnInit } from "@angular/core"; | ||
import { UntypedFormControl } from "@angular/forms"; | ||
import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; | ||
import { MatSnackBar } from "@angular/material/snack-bar"; | ||
import { Organisation } from "@app/admin/organisation/organisation.model"; | ||
import { OrganisationService } from "@app/admin/organisation/organisation.service"; | ||
import { PermissionResponse } from "@app/admin/permission/permission.model"; | ||
import { PermissionService } from "@app/admin/permission/permission.service"; | ||
import { Application, UpdateApplicationOrganization } from "@applications/application.model"; | ||
import { ApplicationService } from "@applications/application.service"; | ||
import { TranslateService } from "@ngx-translate/core"; | ||
import { ApplicationDialogModel } from "@shared/models/dialog.model"; | ||
import { SharedVariableService } from "@shared/shared-variable/shared-variable.service"; | ||
import { ReplaySubject, Subscription } from "rxjs"; | ||
|
||
@Component({ | ||
selector: "app-change-organization-dialog", | ||
templateUrl: "./application-change-organization-dialog.component.html", | ||
styleUrls: ["./application-change-organization-dialog.component.scss"], | ||
}) | ||
export class ApplicationChangeOrganizationDialogComponent implements OnInit { | ||
public applicationsSubscription: Subscription; | ||
public permissionsSubscription: Subscription; | ||
public organizationsSubscription: Subscription; | ||
public application: UpdateApplicationOrganization; | ||
public permissions: PermissionResponse[]; | ||
public organizations: Organisation[]; | ||
public filteredPermissionsMulti: ReplaySubject<PermissionResponse[]> = new ReplaySubject<PermissionResponse[]>(1); | ||
public filteredOrganizations: ReplaySubject<Organisation[]> = new ReplaySubject<Organisation[]>(1); | ||
|
||
constructor( | ||
private applicationService: ApplicationService, | ||
public translate: TranslateService, | ||
private permissionService: PermissionService, | ||
private organizationService: OrganisationService, | ||
private sharedVariableService: SharedVariableService, | ||
private snackBar: MatSnackBar, | ||
private dialog: MatDialogRef<ApplicationChangeOrganizationDialogComponent>, | ||
@Inject(MAT_DIALOG_DATA) public dialogModel: ApplicationDialogModel | ||
) { | ||
this.application = { | ||
organizationId: this.dialogModel.organizationId ?? this.sharedVariableService.getSelectedOrganisationId(), | ||
permissionIds: [], | ||
}; | ||
} | ||
|
||
ngOnInit(): void { | ||
this.translate.use("da"); | ||
if (this.dialogModel.id) { | ||
this.getApplication(this.dialogModel.id); | ||
} | ||
this.getOrganizations(); | ||
this.getPermissions(); | ||
} | ||
|
||
getApplication(id: number): void { | ||
this.applicationsSubscription = this.applicationService.getApplication(id).subscribe((application: Application) => { | ||
this.application.permissionIds = application.permissionIds; | ||
}); | ||
} | ||
|
||
getOrganizations() { | ||
this.organizationsSubscription = this.organizationService.getMinimal().subscribe(res => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get minimal henter altid alle organisationer, man må kun flytte applikationer mellem organisationer man er applikations administrator på. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ja det kan jeg godt se, retter det til findAll, der er der allowed orgs/alle ved global admin |
||
this.organizations = res.data; | ||
this.filteredOrganizations.next(this.organizations.slice()); | ||
}); | ||
} | ||
|
||
getPermissions() { | ||
this.permissionsSubscription = this.permissionService.getPermissions(1000, 0).subscribe(res => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dit get permissions her henter kun for de organisationer hvor brugeren har userAdmin rettighed, hvilket vil sige at man ikke altid kan se alle da permissions ikke er herakiske. (Den bør nok laves om til at lave et fetch for den givne organisations permissions hvis man er applikations admin). Alternativt skal vi lige diskutere den rettighed her med Mogens |
||
this.permissions = res.data.sort((a, b) => a.name.localeCompare(b.name, "da-DK", { numeric: true })); | ||
this.filteredPermissionsMulti.next( | ||
this.permissions.filter(p => p?.organization?.id === this?.application?.organizationId) | ||
); | ||
}); | ||
} | ||
|
||
public compare(o1: any, o2: any): boolean { | ||
return o1 === o2; | ||
} | ||
|
||
onOrganizationChange() { | ||
this.filteredPermissionsMulti.next( | ||
this.permissions.filter(p => p?.organization?.id === this?.application?.organizationId) | ||
); | ||
this.filteredPermissionsMulti.subscribe(res => { | ||
this.application.permissionIds = res | ||
.filter(permission => permission.automaticallyAddNewApplications) | ||
.map(permission => permission.id); | ||
}); | ||
} | ||
|
||
onSubmit() { | ||
this.applicationsSubscription = this.applicationService | ||
.updateApplicationOrganization(this.application, this.dialogModel.id) | ||
.subscribe(savedApplication => { | ||
this.snackBar.open( | ||
this.translate.instant("APPLICATION.CHANGE-ORGANIZATION.SNACKBAR-SAVED", { | ||
applicationName: savedApplication.name, | ||
organizationName: savedApplication.belongsTo.name, | ||
}), | ||
"", | ||
{ | ||
duration: 10000, | ||
} | ||
); | ||
this.dialog.close(true); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ import { map } from "rxjs/operators"; | |
import { SharedVariableService } from "@shared/shared-variable/shared-variable.service"; | ||
import { ChirpstackGatewayService } from "@shared/services/chirpstack-gateway.service"; | ||
import { Gateway, GatewayResponseMany } from "@app/gateway/gateway.model"; | ||
import { MatDialog } from "@angular/material/dialog"; | ||
import { ApplicationChangeOrganizationDialogComponent } from "../application-change-organization-dialog/application-change-organization-dialog.component"; | ||
import { ApplicationDialogModel } from "@shared/models/dialog.model"; | ||
|
||
@Component({ | ||
selector: "app-application", | ||
|
@@ -57,6 +60,7 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy, AfterViewI | |
public redMarker = "/assets/images/red-marker.png"; | ||
public greenMarker = "/assets/images/green-marker.png"; | ||
public greyMarker = "/assets/images/grey-marker.png"; | ||
private dropdownButtonExtraOptionsHandlers: Map<number, () => void> = new Map(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternativet til at have et map med onClick events, er at udvide Dropdown extra options til at kunne holde et onclick event, og så at det bliver kaldt onclick, frem for det event der ellers sendes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Har du da en situation her i hvor du har brug for mere end én handler? Hvis ja. så synes jeg du skal udvide There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Jeg har ikke lige pt en situation med brug for mere end én handler, men det kunne der sagtens være. Jeg anvender den på samme måde i Feature/IOT-1209-MoveGateway, så det ville også gøre det nemmere der. |
||
|
||
constructor( | ||
private applicationService: ApplicationService, | ||
|
@@ -68,7 +72,8 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy, AfterViewI | |
private deleteDialogService: DeleteDialogService, | ||
private restService: RestService, | ||
private sharedVariableService: SharedVariableService, | ||
private chirpstackGatewayService: ChirpstackGatewayService | ||
private chirpstackGatewayService: ChirpstackGatewayService, | ||
private changeOrganizationDialog: MatDialog | ||
) {} | ||
|
||
ngOnInit(): void { | ||
|
@@ -79,7 +84,18 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy, AfterViewI | |
label: "", | ||
editRouterLink: "../edit-application/" + this.id, | ||
isErasable: true, | ||
extraOptions: [], | ||
}; | ||
|
||
this.translate.get("APPLICATION.CHANGE-ORGANIZATION.TITLE").subscribe(translation => { | ||
const changeOrganizationButton = { | ||
id: this.id, | ||
label: translation, | ||
onClick: () => this.onOpenChangeOrganizationDialog(), | ||
}; | ||
this.dropdownButton.extraOptions.push(changeOrganizationButton); | ||
this.dropdownButtonExtraOptionsHandlers.set(changeOrganizationButton.id, changeOrganizationButton.onClick); | ||
}); | ||
} | ||
|
||
this.translate | ||
|
@@ -193,6 +209,21 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy, AfterViewI | |
}); | ||
} | ||
|
||
onOpenChangeOrganizationDialog() { | ||
this.changeOrganizationDialog.open(ApplicationChangeOrganizationDialogComponent, { | ||
data: { | ||
id: this.id, | ||
organizationId: this.application.belongsTo.id, | ||
} as ApplicationDialogModel, | ||
}); | ||
} | ||
|
||
onExtraDropdownOptionClicked(id: string) { | ||
const handler = this.dropdownButtonExtraOptionsHandlers.get(Number(id)); | ||
|
||
handler && handler(); | ||
} | ||
|
||
bindApplication(id: number): void { | ||
this.applicationsSubscription = this.applicationService.getApplication(id).subscribe(application => { | ||
this.application = application; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ export class DialogModel { | |
export class WelcomeDialogModel { | ||
hasSomePermission: boolean; | ||
} | ||
|
||
export class ApplicationDialogModel { | ||
id: number; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename til applicationId |
||
organizationId?: number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Du har det samme id flere gange