use base collections component from jslib
This commit is contained in:
parent
e20a75eb0c
commit
745e6c1715
|
@ -1,12 +1,10 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
|
||||||
import { Angulartics2 } from 'angulartics2';
|
|
||||||
|
|
||||||
import { ApiService } from 'jslib/abstractions/api.service';
|
import { ApiService } from 'jslib/abstractions/api.service';
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
import { CipherData } from 'jslib/models/data/cipherData';
|
import { CipherData } from 'jslib/models/data/cipherData';
|
||||||
import { Cipher } from 'jslib/models/domain/cipher';
|
import { Cipher } from 'jslib/models/domain/cipher';
|
||||||
|
@ -22,10 +20,10 @@ import { CollectionsComponent as BaseCollectionsComponent } from '../../vault/co
|
||||||
export class CollectionsComponent extends BaseCollectionsComponent {
|
export class CollectionsComponent extends BaseCollectionsComponent {
|
||||||
organization: Organization;
|
organization: Organization;
|
||||||
|
|
||||||
constructor(collectionService: CollectionService, analytics: Angulartics2,
|
constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService,
|
||||||
toasterService: ToasterService, i18nService: I18nService,
|
i18nService: I18nService, cipherService: CipherService,
|
||||||
cipherService: CipherService, private apiService: ApiService) {
|
private apiService: ApiService) {
|
||||||
super(collectionService, analytics, toasterService, i18nService, cipherService);
|
super(collectionService, platformUtilsService, i18nService, cipherService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async loadCipher() {
|
protected async loadCipher() {
|
||||||
|
|
|
@ -1,72 +1,31 @@
|
||||||
import {
|
import {
|
||||||
Component,
|
Component,
|
||||||
EventEmitter,
|
|
||||||
Input,
|
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
OnInit,
|
|
||||||
Output,
|
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
import { ToasterService } from 'angular2-toaster';
|
|
||||||
import { Angulartics2 } from 'angulartics2';
|
|
||||||
|
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||||
import { I18nService } from 'jslib/abstractions/i18n.service';
|
import { I18nService } from 'jslib/abstractions/i18n.service';
|
||||||
|
import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service';
|
||||||
|
|
||||||
import { CipherView } from 'jslib/models/view/cipherView';
|
|
||||||
import { CollectionView } from 'jslib/models/view/collectionView';
|
import { CollectionView } from 'jslib/models/view/collectionView';
|
||||||
|
|
||||||
import { Cipher } from 'jslib/models/domain/cipher';
|
import { CollectionsComponent as BaseCollectionsComponent } from 'jslib/angular/components/collections.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-vault-collections',
|
selector: 'app-vault-collections',
|
||||||
templateUrl: 'collections.component.html',
|
templateUrl: 'collections.component.html',
|
||||||
})
|
})
|
||||||
export class CollectionsComponent implements OnInit, OnDestroy {
|
export class CollectionsComponent extends BaseCollectionsComponent implements OnDestroy {
|
||||||
@Input() cipherId: string;
|
constructor(collectionService: CollectionService, platformUtilsService: PlatformUtilsService,
|
||||||
@Output() onSavedCollections = new EventEmitter();
|
i18nService: I18nService, cipherService: CipherService) {
|
||||||
|
super(collectionService, platformUtilsService, i18nService, cipherService);
|
||||||
formPromise: Promise<any>;
|
|
||||||
cipher: CipherView;
|
|
||||||
collectionIds: string[];
|
|
||||||
collections: CollectionView[] = [];
|
|
||||||
|
|
||||||
protected cipherDomain: Cipher;
|
|
||||||
|
|
||||||
constructor(protected collectionService: CollectionService, protected analytics: Angulartics2,
|
|
||||||
protected toasterService: ToasterService, protected i18nService: I18nService,
|
|
||||||
protected cipherService: CipherService) { }
|
|
||||||
|
|
||||||
async ngOnInit() {
|
|
||||||
this.cipherDomain = await this.loadCipher();
|
|
||||||
this.collectionIds = this.loadCipherCollections();
|
|
||||||
this.cipher = await this.cipherDomain.decrypt();
|
|
||||||
this.collections = await this.loadCollections();
|
|
||||||
|
|
||||||
this.selectAll(false);
|
|
||||||
if (this.collectionIds != null) {
|
|
||||||
this.collections.forEach((c) => {
|
|
||||||
(c as any).checked = this.collectionIds != null && this.collectionIds.indexOf(c.id) > -1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
this.selectAll(false);
|
this.selectAll(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
async submit() {
|
|
||||||
this.cipherDomain.collectionIds = this.collections
|
|
||||||
.filter((c) => !!(c as any).checked)
|
|
||||||
.map((c) => c.id);
|
|
||||||
this.formPromise = this.saveCollections();
|
|
||||||
await this.formPromise;
|
|
||||||
this.onSavedCollections.emit();
|
|
||||||
this.analytics.eventTrack.next({ action: 'Edited Cipher Collections' });
|
|
||||||
this.toasterService.popAsync('success', null, this.i18nService.t('editedItem'));
|
|
||||||
}
|
|
||||||
|
|
||||||
check(c: CollectionView, select?: boolean) {
|
check(c: CollectionView, select?: boolean) {
|
||||||
(c as any).checked = select == null ? !(c as any).checked : select;
|
(c as any).checked = select == null ? !(c as any).checked : select;
|
||||||
}
|
}
|
||||||
|
@ -74,21 +33,4 @@ export class CollectionsComponent implements OnInit, OnDestroy {
|
||||||
selectAll(select: boolean) {
|
selectAll(select: boolean) {
|
||||||
this.collections.forEach((c) => this.check(c, select));
|
this.collections.forEach((c) => this.check(c, select));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected loadCipher() {
|
|
||||||
return this.cipherService.get(this.cipherId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected loadCipherCollections() {
|
|
||||||
return this.cipherDomain.collectionIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async loadCollections() {
|
|
||||||
const allCollections = await this.collectionService.getAllDecrypted();
|
|
||||||
return allCollections.filter((c) => !c.readOnly && c.organizationId === this.cipher.organizationId);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected saveCollections() {
|
|
||||||
return this.cipherService.saveCollectionsWithServer(this.cipherDomain);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue