Skip to content

Commit

Permalink
Merge pull request #3556 from jrsquared/execution-group
Browse files Browse the repository at this point in the history
refactor(core/cache): Convert collapsibleSectionStateCache to TS
  • Loading branch information
Justin Reynolds committed Apr 19, 2017
2 parents 1be6487 + 5249870 commit 029f6e8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 39 deletions.
3 changes: 2 additions & 1 deletion app/scripts/modules/core/cache/caches.module.js
@@ -1,8 +1,9 @@
'use strict';

import { COLLAPSIBLE_SECTION_STATE_CACHE } from './collapsibleSectionStateCache';
let angular = require('angular');

module.exports = angular
.module('spinnaker.core.cache', [
require('./collapsibleSectionStateCache.js'),
COLLAPSIBLE_SECTION_STATE_CACHE,
]);
35 changes: 0 additions & 35 deletions app/scripts/modules/core/cache/collapsibleSectionStateCache.js

This file was deleted.

44 changes: 44 additions & 0 deletions app/scripts/modules/core/cache/collapsibleSectionStateCache.ts
@@ -0,0 +1,44 @@
import { ICache, ICacheFactory } from './deckCache.service';
import { module } from 'angular';


export class CollapsibleSectionStateCache {
private stateCache: ICache;

static get $inject(): string[] { return ['CacheFactory']; }
constructor(private CacheFactory: ICacheFactory) {
const cacheId = 'collapsibleSectionStateCache';

try {
this.CacheFactory.createCache(cacheId, {
maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days
deleteOnExpire: 'aggressive',
storageMode: 'localStorage',
});
} catch (e) {
// trying to create a cache multiple times throws and Error
}

this.stateCache = CacheFactory.get(cacheId);
}

public isSet(heading: string): boolean {
return this.stateCache.get(heading) !== undefined;
}

public isExpanded(heading: string): boolean {
return this.stateCache.get(heading) === true;
}

public setExpanded(heading: string, expanded: boolean) {
this.stateCache.put(heading, !!expanded);
}
}

export let collapsibleSectionStateCache: CollapsibleSectionStateCache = undefined;
export const COLLAPSIBLE_SECTION_STATE_CACHE = 'spinnaker.core.cache.collapsibleSectionState';
module(COLLAPSIBLE_SECTION_STATE_CACHE, [
require('angular-cache')
])
.service('collapsibleSectionStateCache', CollapsibleSectionStateCache)
.run(($injector: any) => collapsibleSectionStateCache = <CollapsibleSectionStateCache>$injector.get('collapsibleSectionStateCache'));
4 changes: 3 additions & 1 deletion app/scripts/modules/core/insight/insight.module.ts
@@ -1,8 +1,10 @@
import {module} from 'angular';

import { COLLAPSIBLE_SECTION_STATE_CACHE } from 'core/cache/collapsibleSectionStateCache';

export const INSIGHT_NGMODULE = module('spinnaker.core.insight', [
require('angular-ui-router'),
require('core/cache/collapsibleSectionStateCache'),
COLLAPSIBLE_SECTION_STATE_CACHE,
]);

import './insight.less';
Expand Down
@@ -1,9 +1,11 @@
'use strict';

import { COLLAPSIBLE_SECTION_STATE_CACHE } from 'core/cache/collapsibleSectionStateCache';

let angular = require('angular');

module.exports = angular.module('spinnaker.core.presentation.collapsibleSection.directive', [
require('core/cache/collapsibleSectionStateCache.js')
COLLAPSIBLE_SECTION_STATE_CACHE
])
.directive('collapsibleSection', function(collapsibleSectionStateCache) {
return {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import _ from 'lodash';

import {COLLAPSIBLE_SECTION_STATE_CACHE} from 'core/cache/collapsibleSectionStateCache';
import {CLUSTER_FILTER_SERVICE} from 'core/cluster/filter/clusterFilter.service';
import {TIME_FORMATTERS} from 'core/utils/timeFormatters';
import {URL_BUILDER_SERVICE} from 'core/navigation/urlBuilder.service';
Expand All @@ -13,7 +14,7 @@ require('./projectCluster.less');
module.exports = angular.module('spinnaker.core.projects.dashboard.clusters.projectCluster.directive', [
require('core/account/collapsibleAccountTag.directive.js'),
URL_BUILDER_SERVICE,
require('core/cache/collapsibleSectionStateCache.js'),
COLLAPSIBLE_SECTION_STATE_CACHE,
CLUSTER_FILTER_SERVICE,
TIME_FORMATTERS,
require('../../../healthCounts/healthCounts.directive.js'),
Expand Down

0 comments on commit 029f6e8

Please sign in to comment.