-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(planet): rename app's host to hostParent, add settings for demo
BREAKING CHANGES: should change host to hostParent when register app
- Loading branch information
1 parent
e51746c
commit 1bdb21e
Showing
24 changed files
with
234 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { helpers } from 'ngx-tethys/util'; | ||
const { isString, isNumber } = helpers; | ||
const NUMBER_PREFIX = `____n____`; | ||
|
||
const SupportedStorage = window && window.localStorage; | ||
const storageSource = window.localStorage || window.sessionStorage; | ||
|
||
const cache = { | ||
/** | ||
* set item to local storage | ||
* | ||
* @example | ||
* cache.set('key1', 'key1-value'); | ||
* cache.set('key1', 10); | ||
* cache.set('key1', { id: 1, name: 'name 1'}); | ||
* cache.set('key1', 'key1-value', false); | ||
* @param key string | ||
* @param value string | number | object | ||
*/ | ||
set<TValue = string>(key: string, value: TValue) { | ||
const itemValue = isString(value) | ||
? value | ||
: isNumber(value) | ||
? `${NUMBER_PREFIX}${value}` | ||
: JSON.stringify(value); | ||
if (SupportedStorage) { | ||
storageSource.setItem(key, itemValue as string); | ||
} | ||
}, | ||
/** | ||
* get item from local storage | ||
* | ||
* @example | ||
* cache.get('key1'); | ||
* cache.get<number>('key1'); | ||
* cache.get<User>('key1'); | ||
* cache.get<User[]>('key1'); | ||
* cache.get('key1', false); | ||
* | ||
* @param key string | ||
*/ | ||
get<TValue = string>(key: string): TValue { | ||
if (SupportedStorage) { | ||
const value = storageSource.getItem(key); | ||
if (value) { | ||
try { | ||
const result = JSON.parse(value); | ||
return result; | ||
} catch (error) { | ||
if (isString(value) && value.includes(NUMBER_PREFIX)) { | ||
return parseInt(value.replace(NUMBER_PREFIX, ''), 10) as any; | ||
} else { | ||
return value as any; | ||
} | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
}, | ||
/** | ||
* remove key from storage | ||
* @param key cache key | ||
*/ | ||
remove(key: string) { | ||
if (SupportedStorage) { | ||
storageSource.removeItem(key); | ||
} | ||
}, | ||
/** | ||
* clear all storage | ||
*/ | ||
clear() { | ||
if (SupportedStorage) { | ||
storageSource.clear(); | ||
} | ||
} | ||
}; | ||
|
||
export { cache }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './app-root-context'; | ||
export * from './module'; | ||
export * from './cache'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { cache } from '@demo/common'; | ||
import { SwitchModes } from 'ngx-planet'; | ||
const SETTINGS_KEY = 'custom-settings'; | ||
|
||
export interface CustomSettingsInfo { | ||
app1: { | ||
preload: boolean; | ||
switchMode?: SwitchModes; | ||
}; | ||
app2: { | ||
preload: boolean; | ||
switchMode?: SwitchModes; | ||
}; | ||
} | ||
|
||
const DEFAULT_SETTINGS: CustomSettingsInfo = { | ||
app1: { | ||
preload: true, | ||
switchMode: SwitchModes.coexist | ||
}, | ||
app2: { | ||
preload: true, | ||
switchMode: SwitchModes.coexist | ||
} | ||
}; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class CustomSettingsService { | ||
get(): CustomSettingsInfo { | ||
const settings = cache.get<CustomSettingsInfo>(SETTINGS_KEY); | ||
return settings || JSON.parse(JSON.stringify(DEFAULT_SETTINGS)); | ||
} | ||
|
||
save(settings: CustomSettingsInfo) { | ||
cache.set<CustomSettingsInfo>(SETTINGS_KEY, settings); | ||
} | ||
|
||
restore() { | ||
cache.set<CustomSettingsInfo>(SETTINGS_KEY, DEFAULT_SETTINGS); | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
examples/portal/src/app/host-container/host-container.component.spec.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
examples/portal/src/app/host-container/host-container.component.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
<section-card title="Settings"> | ||
<label thyCheckbox name="app1-preload" thyLabelText="App1 Preload"></label> | ||
<label thyCheckbox name="app2-preload" thyLabelText="App2 Preload"></label> | ||
<form thyForm name="settings"> | ||
<thy-form-group thyLabelText="Preload" thyLabelPaddingTopClear="true"> | ||
<label thyCheckbox name="app1-preload" thyLabelText="App1 Preload" [(ngModel)]="settings.app1.preload"></label> | ||
<label thyCheckbox name="app2-preload" thyLabelText="App2 Preload" [(ngModel)]="settings.app2.preload"></label> | ||
</thy-form-group> | ||
|
||
<thy-form-group thyLabelText="App1 Switch Mode" thyLabelPaddingTopClear="true"> | ||
<thy-radio-group name="app1SwitchMode" [(ngModel)]="settings.app1.switchMode" thyLayout="flex" required> | ||
<label thyRadio thyLabelText="Default (Destroy App when not active)" thyValue="default"></label> | ||
<label thyRadio thyLabelText="Coexist (Hide App when when not active)" thyValue="coexist"></label> | ||
</thy-radio-group> | ||
</thy-form-group> | ||
|
||
<thy-form-group thyLabelText="App2 Switch Mode" thyLabelPaddingTopClear="true"> | ||
<thy-radio-group name="app2SwitchMode" [(ngModel)]="settings.app2.switchMode" thyLayout="flex" required> | ||
<label thyRadio thyLabelText="Default (Destroy App when not active)" thyValue="default"></label> | ||
<label thyRadio thyLabelText="Coexist (Hide App when when not active)" thyValue="coexist"></label> | ||
</thy-radio-group> | ||
</thy-form-group> | ||
|
||
<thy-form-group-footer> | ||
<button thyButton="primary" (thyFormSubmit)="save()">Save</button> | ||
<button thyButton="link-secondary" (click)="reset()">Reset</button> | ||
<button thyButton="outline-info" (click)="restore()">Restore to default</button> | ||
</thy-form-group-footer> | ||
<!-- <thy-form-group> | ||
{{ settings | json }} | ||
</thy-form-group> --> | ||
</form> | ||
</section-card> |
Oops, something went wrong.