Skip to content

Commit

Permalink
LocalStorage : store columns
Browse files Browse the repository at this point in the history
Fix #305
  • Loading branch information
t8g committed Feb 14, 2017
1 parent 165151d commit 94dbdfc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 4 additions & 2 deletions client/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { CVComponent } from './cv/cv.component';
import { FocusMeDirective } from './fields/focus-me.directive';
import { ConfirmDialog } from './fields/confirm.component';
import { IsariCreationModal } from './isari-creation-modal/isari-creation-modal.component';
import { StorageService } from './storage.service';

export function createTranslateLoader(http: Http) {
return new TranslateStaticLoader(http, './assets/i18n', '.json');
Expand Down Expand Up @@ -80,7 +81,7 @@ export function createTranslateLoader(http: Http) {
CVComponent,
FocusMeDirective,
ConfirmDialog,
IsariCreationModal
IsariCreationModal,
],
imports: [
BrowserModule,
Expand All @@ -102,11 +103,12 @@ export function createTranslateLoader(http: Http) {
UserService,
LoggedInGuard,
OrganizationResolver,
StorageService,
],
entryComponents: [
AppComponent,
ConfirmDialog,
IsariCreationModal
IsariCreationModal,
],
bootstrap: [
AppComponent,
Expand Down
19 changes: 14 additions & 5 deletions client/src/app/isari-list/isari-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IsariDataService } from '../isari-data.service';
import { TranslateService } from 'ng2-translate';
import { MdDialogRef, MdDialog } from '@angular/material';
import { IsariCreationModal } from '../isari-creation-modal/isari-creation-modal.component';
import { StorageService } from '../storage.service';

@Component({
selector: 'isari-list',
Expand All @@ -31,6 +32,7 @@ export class IsariListComponent implements OnInit {
activityTypeLabel: string;

constructor (
private StorageService: StorageService,
private route: ActivatedRoute,
private isariDataService: IsariDataService,
private translate: TranslateService,
Expand Down Expand Up @@ -62,11 +64,17 @@ export class IsariListComponent implements OnInit {
this.cols = columns;
});

this.isariDataService.getColumnsWithDefault(feature)
.then(defaultColumns => {
this.selectedColumns = defaultColumns;
this.loadDatas();
});
this.selectedColumns = this.StorageService.get('colSelected', this.feature);
if (!this.selectedColumns) {
this.isariDataService.getColumnsWithDefault(feature)
.then(defaultColumns => {
this.selectedColumns = defaultColumns;
this.loadDatas();
});
} else {
this.loadDatas();
}


});

Expand All @@ -93,6 +101,7 @@ export class IsariListComponent implements OnInit {
}

colSelected($event) {
this.StorageService.save($event.cols, 'colSelected', this.feature);
this.selectedColumns = $event.cols;
this.loadDatas();
}
Expand Down
14 changes: 14 additions & 0 deletions client/src/app/storage.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';

@Injectable()
export class StorageService {

save(value, key, feature) {
localStorage.setItem(`${feature}.${key}`, JSON.stringify(value));
}

get(key, feature) {
return JSON.parse(localStorage.getItem(`${feature}.${key}`));
}

}

0 comments on commit 94dbdfc

Please sign in to comment.