Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
added collpase/expand functions to groupings
Browse files Browse the repository at this point in the history
  • Loading branch information
kspearrin committed Nov 9, 2018
1 parent b4fad20 commit 786fa02
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/angular/components/groupings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import { TreeNode } from '../../models/domain/treeNode';

import { CollectionService } from '../../abstractions/collection.service';
import { FolderService } from '../../abstractions/folder.service';
import { StorageService } from '../../abstractions/storage.service';
import { UserService } from '../../abstractions/user.service';

import { ConstantsService } from '../../services/constants.service';

export class GroupingsComponent {
@Input() showFolders = true;
Expand Down Expand Up @@ -40,9 +44,22 @@ export class GroupingsComponent {
selectedFolderId: string = null;
selectedCollectionId: string = null;

constructor(protected collectionService: CollectionService, protected folderService: FolderService) { }
private collapsedGroupings: Set<string>;
private collapsedGroupingsKey: string;

constructor(protected collectionService: CollectionService, protected folderService: FolderService,
protected storageService: StorageService, protected userService: UserService) { }

async load(setLoaded = true) {
const userId = await this.userService.getUserId();
this.collapsedGroupingsKey = ConstantsService.collapsedGroupingsKey + '_' + userId;
const collapsedGroupings = await this.storageService.get<string[]>(this.collapsedGroupingsKey);
if (collapsedGroupings == null) {
this.collapsedGroupings = new Set<string>();
} else {
this.collapsedGroupings = new Set(collapsedGroupings);
}

await this.loadFolders();
await this.loadCollections();

Expand Down Expand Up @@ -119,4 +136,21 @@ export class GroupingsComponent {
this.selectedFolderId = null;
this.selectedCollectionId = null;
}

collapse(grouping: FolderView | CollectionView, idPrefix = '') {
if (grouping.id == null) {
return;
}
const id = idPrefix + grouping.id;
if (this.isCollapsed(grouping, idPrefix)) {
this.collapsedGroupings.delete(id);
} else {
this.collapsedGroupings.add(id);
}
this.storageService.save(this.collapsedGroupingsKey, this.collapsedGroupings);
}

isCollapsed(grouping: FolderView | CollectionView, idPrefix = '') {
return this.collapsedGroupings.has(idPrefix + grouping.id);
}
}
2 changes: 2 additions & 0 deletions src/services/constants.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ConstantsService {
static readonly installedVersionKey: string = 'installedVersion';
static readonly localeKey: string = 'locale';
static readonly themeKey: string = 'theme';
static readonly collapsedGroupingsKey: string = 'collapsedGroupings';

readonly environmentUrlsKey: string = ConstantsService.environmentUrlsKey;
readonly disableGaKey: string = ConstantsService.disableGaKey;
Expand All @@ -27,4 +28,5 @@ export class ConstantsService {
readonly installedVersionKey: string = ConstantsService.installedVersionKey;
readonly localeKey: string = ConstantsService.localeKey;
readonly themeKey: string = ConstantsService.themeKey;
readonly collapsedGroupingsKey: string = ConstantsService.collapsedGroupingsKey;
}

0 comments on commit 786fa02

Please sign in to comment.