1
0
mirror of https://github.com/bitwarden/web synced 2025-12-21 10:43:26 +00:00

group add/edit/delete

This commit is contained in:
Kyle Spearrin
2018-07-09 16:27:54 -04:00
parent b774091b83
commit ecfecd295a
13 changed files with 383 additions and 46 deletions

View File

@@ -1,28 +1,44 @@
import {
Component,
ComponentFactoryResolver,
OnInit,
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ToasterService } from 'angular2-toaster';
import { Angulartics2 } from 'angulartics2';
import { ApiService } from 'jslib/abstractions/api.service';
import { I18nService } from 'jslib/abstractions/i18n.service';
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
import { GroupResponse } from 'jslib/models/response/groupResponse';
import { Utils } from 'jslib/misc/utils';
import { ModalComponent } from '../../modal.component';
import { GroupAddEditComponent } from './group-add-edit.component';
@Component({
selector: 'app-org-groups',
templateUrl: 'groups.component.html',
})
export class GroupsComponent implements OnInit {
@ViewChild('addEdit', { read: ViewContainerRef }) addEditModalRef: ViewContainerRef;
loading = true;
organizationId: string;
groups: GroupResponse[];
searchText: string;
private modal: ModalComponent = null;
constructor(private apiService: ApiService, private route: ActivatedRoute,
private i18nService: I18nService) { }
private i18nService: I18nService, private componentFactoryResolver: ComponentFactoryResolver,
private analytics: Angulartics2, private toasterService: ToasterService,
private platformUtilsService: PlatformUtilsService) { }
async ngOnInit() {
this.route.parent.parent.params.subscribe(async (params) => {
@@ -38,4 +54,51 @@ export class GroupsComponent implements OnInit {
this.groups = groups;
this.loading = false;
}
edit(group: GroupResponse) {
if (this.modal != null) {
this.modal.close();
}
const factory = this.componentFactoryResolver.resolveComponentFactory(ModalComponent);
this.modal = this.addEditModalRef.createComponent(factory).instance;
const childComponent = this.modal.show<GroupAddEditComponent>(
GroupAddEditComponent, this.addEditModalRef);
childComponent.organizationId = this.organizationId;
childComponent.groupId = group != null ? group.id : null;
childComponent.onSavedGroup.subscribe(() => {
this.modal.close();
this.load();
});
childComponent.onDeletedGroup.subscribe(() => {
this.modal.close();
this.load();
});
this.modal.onClosed.subscribe(() => {
this.modal = null;
});
}
add() {
this.edit(null);
}
async delete(group: GroupResponse) {
const confirmed = await this.platformUtilsService.showDialog(
this.i18nService.t('deleteGroupConfirmation'), group.name,
this.i18nService.t('yes'), this.i18nService.t('no'), 'warning');
if (!confirmed) {
return false;
}
try {
await this.apiService.deleteGroup(this.organizationId, group.id);
this.analytics.eventTrack.next({ action: 'Deleted Group' });
this.toasterService.popAsync('success', null,
this.i18nService.t('deletedThing', this.i18nService.t('group').toLocaleLowerCase(), group.name));
await this.load();
} catch { }
}
}