├── src ├── assets │ └── .gitkeep ├── app │ ├── add-toggle-modal │ │ ├── add-toggle-modal.component.scss │ │ ├── add-toggle-modal.component.html │ │ ├── add-toggle-modal.component.ts │ │ └── add-toggle-modal.component.spec.ts │ ├── config-properties │ │ ├── config-properties.component.scss │ │ ├── config-properties.component.html │ │ ├── config-properties.component.ts │ │ └── config-properties.component.spec.ts │ ├── index.ts │ ├── state-management │ │ ├── app │ │ │ ├── app.model.ts │ │ │ ├── index.ts │ │ │ ├── app.actions.ts │ │ │ ├── app.reducers.ts │ │ │ ├── app.reducers.spec.ts │ │ │ └── app.effects.ts │ │ ├── properties │ │ │ ├── index.ts │ │ │ ├── properties.actions.ts │ │ │ ├── properties.reducers.ts │ │ │ └── properties.reducers.spec.ts │ │ ├── apps │ │ │ ├── index.ts │ │ │ ├── apps.actions.ts │ │ │ ├── apps.reducers.ts │ │ │ ├── apps.reducers.spec.ts │ │ │ └── apps.effects.ts │ │ └── feature-toggles │ │ │ ├── feature-toggle.model.ts │ │ │ ├── index.ts │ │ │ ├── feature-toggles.actions.ts │ │ │ ├── feature-toggles.reducers.ts │ │ │ └── feature-toggles.reducers.spec.ts │ ├── app.component.scss │ ├── shared │ │ └── pipes │ │ │ └── filter.pipe.ts │ ├── feature-toggles │ │ ├── feature-toggles.component.scss │ │ ├── feature-toggles.component.html │ │ ├── feature-toggles.component.ts │ │ └── feature-toggles.component.spec.ts │ ├── app.component.ts │ ├── app.component.html │ ├── app.module.ts │ └── app.component.spec.ts ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── typings.d.ts ├── main.ts ├── index.html ├── styles.scss ├── tsconfig.json ├── polyfills.ts └── test.ts ├── .dockerignore ├── docker-compose.yml ├── Dockerfile ├── e2e ├── app.po.ts ├── tsconfig.json └── app.e2e-spec.ts ├── .editorconfig ├── .gitignore ├── .travis.yml ├── protractor.conf.js ├── nginx.conf ├── karma.conf.js ├── angular-cli.json ├── package.json ├── README.md └── tslint.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/add-toggle-modal/add-toggle-modal.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/config-properties/config-properties.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !dist 3 | !nginx.conf 4 | !db.json 5 | !start.sh 6 | -------------------------------------------------------------------------------- /src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joaoflf/remote-config-dashboard/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/app/config-properties/config-properties.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
-------------------------------------------------------------------------------- /src/app/state-management/app/app.model.ts: -------------------------------------------------------------------------------- 1 | export interface App { 2 | id: String; 3 | name: String; 4 | } 5 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | web: 4 | build: . 5 | ports: 6 | - "80:80" 7 | -------------------------------------------------------------------------------- /src/app/state-management/properties/index.ts: -------------------------------------------------------------------------------- 1 | export * from './properties.reducers'; 2 | export * from './properties.actions'; 3 | 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM nginx:alpine 2 | 3 | COPY nginx.conf /etc/nginx/conf.d/default.conf 4 | COPY dist /usr/share/nginx/html 5 | 6 | EXPOSE 80 7 | 8 | -------------------------------------------------------------------------------- /src/app/state-management/apps/index.ts: -------------------------------------------------------------------------------- 1 | export * from './apps.reducers'; 2 | export * from './apps.actions'; 3 | export * from './apps.effects'; 4 | -------------------------------------------------------------------------------- /src/app/state-management/apps/apps.actions.ts: -------------------------------------------------------------------------------- 1 | export const LOAD_APPS = 'LOAD_APPS'; 2 | export const LOAD_APPS_SUCCESS = 'LOAD_APPS_SUCCESS'; 3 | 4 | -------------------------------------------------------------------------------- /src/app/state-management/feature-toggles/feature-toggle.model.ts: -------------------------------------------------------------------------------- 1 | export interface FeatureToggle { 2 | name: String; 3 | state: boolean; 4 | } 5 | -------------------------------------------------------------------------------- /src/app/state-management/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.model'; 2 | export * from './app.reducers'; 3 | export * from './app.actions'; 4 | export * from './app.effects'; 5 | -------------------------------------------------------------------------------- /src/app/state-management/app/app.actions.ts: -------------------------------------------------------------------------------- 1 | export const UPDATE_APP_NAME = 'UPDATE_APP_NAME'; 2 | export const LOAD_APP = 'LOAD_APP'; 3 | export const LOAD_APP_SUCCESS = 'LOAD_APP_SUCCESS'; -------------------------------------------------------------------------------- /src/app/state-management/feature-toggles/index.ts: -------------------------------------------------------------------------------- 1 | export * from './feature-toggles.reducers'; 2 | export * from './feature-toggles.actions'; 3 | export * from './feature-toggle.model'; 4 | -------------------------------------------------------------------------------- /src/app/state-management/properties/properties.actions.ts: -------------------------------------------------------------------------------- 1 | export const UPDATE_PROPERTIES = 'UPDATE_PROPERTIES'; 2 | export const LOAD_PROPERTIES_SUCCESS = 'LOAD_PROPERTIES_SUCCESS'; 3 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | .app-title { 2 | margin: 0; 3 | padding-top: 4px; 4 | } 5 | 6 | .tabs { 7 | margin: 10px 0 0 0; 8 | } 9 | 10 | .panel { 11 | margin-top: 20px; 12 | } -------------------------------------------------------------------------------- /src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, you can add your own global typings here 2 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 3 | 4 | declare var System: any; 5 | -------------------------------------------------------------------------------- /e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class RemoteConfigDashboardPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = 0 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /src/app/state-management/feature-toggles/feature-toggles.actions.ts: -------------------------------------------------------------------------------- 1 | export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE'; 2 | export const REMOVE_FEATURE_TOGGLE = 'REMOVE_FEATURE_TOGGLE'; 3 | export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE'; 4 | export const LOAD_TOGGLES_SUCCESS = 'LOAD_TOGGLES_SUCCESS'; 5 | 6 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 2 | import { enableProdMode } from '@angular/core'; 3 | import { environment } from './environments/environment'; 4 | import { AppModule } from './app/'; 5 | 6 | if (environment.production) { 7 | enableProdMode(); 8 | } 9 | 10 | platformBrowserDynamic().bootstrapModule(AppModule); 11 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Remote Config Dashboard 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Loading... 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | div.jsoneditor-tree { 4 | min-height: 250px; 5 | } 6 | 7 | .jsoneditor { 8 | border-color: #006a91 !important; 9 | } 10 | 11 | div.jsoneditor-menu { 12 | border-color: #006a91 !important; 13 | background-color: #006a91 !important; 14 | } 15 | 16 | *:focus { 17 | outline: none !important; 18 | } -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { RemoteConfigDashboardPage } from './app.po'; 2 | 3 | describe('remote-config-dashboard App', function() { 4 | let page: RemoteConfigDashboardPage; 5 | 6 | beforeEach(() => { 7 | page = new RemoteConfigDashboardPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /src/app/shared/pipes/filter.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | 3 | @Pipe({ 4 | name: 'filter' 5 | }) 6 | export class FilterPipe implements PipeTransform { 7 | 8 | transform(items: any[], filter: string): any { 9 | if(!items || !filter) { 10 | return items; 11 | } 12 | return items.filter(item => JSON.stringify(item).toLowerCase().indexOf(filter.toLowerCase()) !== -1); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /src/app/state-management/apps/apps.reducers.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_APPS, LOAD_APPS_SUCCESS } from './apps.actions'; 2 | import { Action } from '@ngrx/store'; 3 | 4 | export function apps(appsState = [], action: Action) { 5 | switch (action.type) { 6 | case LOAD_APPS_SUCCESS: 7 | return [...action.payload]; 8 | case LOAD_APPS: 9 | return appsState; 10 | default: { 11 | return appsState; 12 | } 13 | } 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": false, 4 | "emitDecoratorMetadata": true, 5 | "experimentalDecorators": true, 6 | "lib": ["es6", "dom"], 7 | "mapRoot": "./", 8 | "module": "es6", 9 | "moduleResolution": "node", 10 | "outDir": "../dist/out-tsc", 11 | "sourceMap": true, 12 | "target": "es5", 13 | "typeRoots": [ 14 | "../node_modules/@types" 15 | ] 16 | } 17 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # IDEs and editors 12 | /.idea 13 | /.vscode 14 | .project 15 | .classpath 16 | *.launch 17 | .settings/ 18 | 19 | # misc 20 | /.sass-cache 21 | /connect.lock 22 | /coverage/* 23 | /libpeerconnection.log 24 | npm-debug.log 25 | testem.log 26 | /typings 27 | 28 | # e2e 29 | /e2e/*.js 30 | /e2e/*.map 31 | 32 | #System Files 33 | .DS_Store 34 | Thumbs.db 35 | -------------------------------------------------------------------------------- /src/app/state-management/properties/properties.reducers.ts: -------------------------------------------------------------------------------- 1 | import { UPDATE_PROPERTIES, LOAD_PROPERTIES_SUCCESS } from './properties.actions'; 2 | import { Action } from '@ngrx/store'; 3 | 4 | export function properties(propertiesState = {}, action: Action) { 5 | switch (action.type) { 6 | 7 | case LOAD_PROPERTIES_SUCCESS: 8 | return { ...action.payload}; 9 | case UPDATE_PROPERTIES: 10 | return { ...propertiesState, ...action.payload}; 11 | default: { 12 | return propertiesState; 13 | } 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular 2 and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /src/app/state-management/app/app.reducers.ts: -------------------------------------------------------------------------------- 1 | import { UPDATE_APP_NAME, LOAD_APP_SUCCESS } from './app.actions'; 2 | import { Action } from '@ngrx/store'; 3 | 4 | export function app(appState = {}, action: Action) { 5 | let id: String, name: String; 6 | switch (action.type) { 7 | 8 | case UPDATE_APP_NAME: 9 | ({ name } = action.payload); 10 | return { ...appState, name: name }; 11 | case LOAD_APP_SUCCESS: 12 | ({ id } = action.payload); 13 | ({ name } = action.payload); 14 | return { ...appState, id: id, name: name }; 15 | default: { 16 | return appState; 17 | } 18 | } 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /src/app/feature-toggles/feature-toggles.component.scss: -------------------------------------------------------------------------------- 1 | .toggles-table { 2 | padding: 0; 3 | margin: 0; 4 | box-shadow: 2px 3px 4px -1px rgba(0, 0, 0, 0.1); 5 | td { 6 | vertical-align: middle; 7 | } 8 | .toggle-switch { 9 | margin: 0; 10 | } 11 | } 12 | 13 | .remove-toggle-button { 14 | margin-right: 0; 15 | } 16 | 17 | .new-toggle-button { 18 | margin: 0; 19 | } 20 | 21 | .actions-header { 22 | text-align: right; 23 | padding: 10px 12px; 24 | } 25 | 26 | .actions-cell { 27 | text-align: right; 28 | padding: 10px 12px; 29 | } 30 | 31 | .toggle-name-header, 32 | .toggle-name-cell { 33 | padding-left: 20px; 34 | text-align: left; 35 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - '7.0.0' 6 | 7 | addons: 8 | apt: 9 | sources: 10 | - google-chrome 11 | packages: 12 | - google-chrome-stable 13 | - google-chrome-beta 14 | 15 | before_install: 16 | - export CHROME_BIN=chromium-browser 17 | - export DISPLAY=:99.0 18 | - sh -e /etc/init.d/xvfb start 19 | 20 | before_script: 21 | - npm install -g @angular/cli 22 | - npm install -g angular-cli-ghpages 23 | - npm install 24 | 25 | script: 26 | - ng test --single-run 27 | - ng build --prod --base-href "https://joaoflf.github.io/remote-config-dashboard/" --aot=false 28 | - angular-cli-ghpages --no-silent --repo=https://GH_TOKEN@github.com/joaoflf/remote-config-dashboard.git -------------------------------------------------------------------------------- /src/app/state-management/app/app.reducers.spec.ts: -------------------------------------------------------------------------------- 1 | import {UPDATE_APP_NAME} from '.'; 2 | import { app } from '.'; 3 | 4 | 5 | describe('app reducer', () => { 6 | it('should return current state when no valid actions have been made', () => { 7 | const state = { id: '1', name: 'Web App' }; 8 | const actual = app(state, { type: 'INVALID_ACTION', payload: {} }); 9 | const expected = state; 10 | expect(actual).toBe(expected); 11 | }); 12 | 13 | it('should update an app name', () => { 14 | const state = { id: '1', name: 'Web App' }; 15 | const actual = app(state, { type: UPDATE_APP_NAME, 16 | payload: {id: '1', name: 'testApp2'}}); 17 | const expected = {id: '1', name: 'testApp2'}; 18 | expect(actual).toEqual(expected); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/app/state-management/apps/apps.reducers.spec.ts: -------------------------------------------------------------------------------- 1 | import {LOAD_APPS_SUCCESS} from '.'; 2 | import { apps } from '.'; 3 | 4 | 5 | describe('apps reducer', () => { 6 | it('should return current state when no valid actions have been made', () => { 7 | const state = []; 8 | const actual = apps(state, { type: 'INVALID_ACTION', payload: {} }); 9 | const expected = state; 10 | expect(actual).toBe(expected); 11 | }); 12 | 13 | it('should load apps', () => { 14 | const state = []; 15 | const actual = apps(state, { type: LOAD_APPS_SUCCESS, 16 | payload: [{id: '1', name: 'testApp1'} , {id: '2', name: 'testApp2'} ]}); 17 | const expected = [{id: '1', name: 'testApp1'} , {id: '2', name: 'testApp2'} ]; 18 | expect(actual).toEqual(expected); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/app/state-management/apps/apps.effects.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Http } from '@angular/http'; 3 | import { Actions, Effect } from '@ngrx/effects'; 4 | import { Observable } from 'rxjs/Observable'; 5 | import { LOAD_APPS, LOAD_APPS_SUCCESS } from './apps.actions'; 6 | import 'rxjs/add/operator/switchMap'; 7 | import 'rxjs/add/operator/map'; 8 | 9 | @Injectable() 10 | export class AppsEffects { 11 | constructor( 12 | private http: Http, 13 | private actions$: Actions 14 | ) {} 15 | 16 | @Effect() appLaunch$ = this.actions$ 17 | .ofType(LOAD_APPS) 18 | .switchMap(() => this.http.get('https://demo6219157.mockable.io/apps') 19 | .map(res => res.json())) 20 | .map(apps => { 21 | return { 22 | type: LOAD_APPS_SUCCESS, 23 | payload: apps 24 | } 25 | }); 26 | } -------------------------------------------------------------------------------- /protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/docs/referenceConf.js 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /src/app/state-management/properties/properties.reducers.spec.ts: -------------------------------------------------------------------------------- 1 | import {UPDATE_PROPERTIES} from '.'; 2 | import { properties } from '.'; 3 | 4 | 5 | describe('properties reducer', () => { 6 | it('should return current state when no valid actions have been made', () => { 7 | const state = {}; 8 | const actual = properties(state, { type: 'INVALID_ACTION', payload: {} }); 9 | const expected = state; 10 | expect(actual).toBe(expected); 11 | }); 12 | 13 | it('should update properties', () => { 14 | const state = {property1: 'testValue', property2: 'testValue2'}; 15 | const actual = properties(state, { type: UPDATE_PROPERTIES, 16 | payload: {property1: 'modifiedTestValue', property2: 'testValue2'} }); 17 | const expected = {property1: 'modifiedTestValue', property2: 'testValue2'}; 18 | expect(actual).toEqual(expected); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | import 'zone.js/dist/long-stack-trace-zone'; 2 | import 'zone.js/dist/proxy.js'; 3 | import 'zone.js/dist/sync-test'; 4 | import 'zone.js/dist/jasmine-patch'; 5 | import 'zone.js/dist/async-test'; 6 | import 'zone.js/dist/fake-async-test'; 7 | 8 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 9 | declare var __karma__: any; 10 | declare var require: any; 11 | 12 | // Prevent Karma from running prematurely. 13 | __karma__.loaded = function () {}; 14 | 15 | 16 | Promise.all([ 17 | System.import('@angular/core/testing'), 18 | System.import('@angular/platform-browser-dynamic/testing') 19 | ]) 20 | // First, initialize the Angular testing environment. 21 | .then(([testing, testingBrowser]) => { 22 | testing.getTestBed().initTestEnvironment( 23 | testingBrowser.BrowserDynamicTestingModule, 24 | testingBrowser.platformBrowserDynamicTesting() 25 | ); 26 | }) 27 | // Then we find all the tests. 28 | .then(() => require.context('./', true, /\.spec\.ts/)) 29 | // And load the modules. 30 | .then(context => context.keys().map(context)) 31 | // Finally, start Karma to run the tests. 32 | .then(__karma__.start, __karma__.error); 33 | -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | 4 | charset utf-8; 5 | 6 | sendfile on; 7 | 8 | root /usr/share/nginx/html; 9 | 10 | ## 11 | # Gzip Settings 12 | ## 13 | gzip on; 14 | gzip_http_version 1.1; 15 | gzip_disable "MSIE [1-6]\."; 16 | gzip_min_length 1100; 17 | gzip_vary on; 18 | gzip_proxied expired no-cache no-store private auth; 19 | gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; 20 | gzip_comp_level 9; 21 | 22 | #Caches static assets 23 | location ~ ^/(assets|bower_components|scripts|styles|views) { 24 | expires 31d; 25 | add_header Cache-Control public; 26 | } 27 | 28 | #Caches Bundles created by angular cli 29 | location ~* \.(?:bundle.js|bundle.css)$ { 30 | expires 1M; 31 | access_log off; 32 | add_header Cache-Control "public"; 33 | } 34 | 35 | ## 36 | # Main file index.html sending not found locations to the main 37 | ## 38 | location / { 39 | expires -1; 40 | add_header Pragma "no-cache"; 41 | add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"; 42 | 43 | try_files $uri $uri/ /index.html = 404; 44 | } 45 | } -------------------------------------------------------------------------------- /src/app/config-properties/config-properties.component.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs/Rx'; 2 | import { Store } from '@ngrx/store'; 3 | import { UPDATE_PROPERTIES } from '../state-management/properties'; 4 | import { Component, OnInit, OnChanges, Input, SimpleChange } from '@angular/core'; 5 | 6 | declare var JSONEditor; 7 | 8 | @Component({ 9 | selector: 'app-config-properties', 10 | templateUrl: './config-properties.component.html', 11 | styleUrls: ['./config-properties.component.scss'] 12 | }) 13 | export class ConfigPropertiesComponent { 14 | 15 | editor: any; 16 | 17 | constructor(private store: Store) { 18 | this.store = store; 19 | } 20 | 21 | ngAfterViewInit() { 22 | let editorOptions = { 23 | modes: ['tree', 'code'], 24 | onChange: this.onJsonEditorChange.bind(this) 25 | }; 26 | this.store.select('properties').subscribe((properties) => { 27 | if (!this.editor) { 28 | let templateDivRef = document.getElementById('jsoneditor'); 29 | this.editor = new JSONEditor(templateDivRef, editorOptions, properties); 30 | } 31 | else { 32 | this.editor.set(properties); 33 | } 34 | }); 35 | } 36 | 37 | onJsonEditorChange() { 38 | this.store.dispatch({ 39 | type: UPDATE_PROPERTIES, 40 | payload: this.editor.get() 41 | }); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/app/state-management/app/app.effects.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_TOGGLES_SUCCESS } from '../feature-toggles/feature-toggles.actions'; 2 | import { LOAD_PROPERTIES_SUCCESS } from '../properties'; 3 | import { Injectable } from '@angular/core'; 4 | import { Http } from '@angular/http'; 5 | import { Actions, Effect } from '@ngrx/effects'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { LOAD_APP, LOAD_APP_SUCCESS } from './app.actions'; 8 | import 'rxjs/add/operator/switchMap'; 9 | import 'rxjs/add/operator/mergeMap'; 10 | import 'rxjs/add/observable/from'; 11 | 12 | @Injectable() 13 | export class AppEffects { 14 | constructor( 15 | private http: Http, 16 | private actions$: Actions 17 | ) { } 18 | 19 | @Effect() loadApp$ = this.actions$ 20 | .ofType(LOAD_APP) 21 | .switchMap(action => this.http.get 22 | ('https://demo6219157.mockable.io/apps/' + action.payload.id) 23 | .map(res => res.json())) 24 | .mergeMap((app) => { 25 | 26 | return Observable.from([ 27 | { 28 | type: LOAD_APP_SUCCESS, 29 | payload: { id: app.id, name: app.name } 30 | }, 31 | { 32 | type: LOAD_PROPERTIES_SUCCESS, 33 | payload: app.properties 34 | }, 35 | { 36 | type: LOAD_TOGGLES_SUCCESS, 37 | payload: app.featureToggles 38 | } 39 | ]) 40 | } 41 | ); 42 | } -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-jasmine-html-reporter'), 11 | require('karma-teamcity-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('karma-chrome-launcher'), 14 | require('@angular/cli/plugins/karma') 15 | ], 16 | client: { 17 | clearContext: false // leave Jasmine Spec Runner output visible in browser 18 | }, 19 | mime: { 'text/x-typescript': ['ts', 'tsx'] }, 20 | files: [ 21 | { pattern: './src/test.ts', watched: false } 22 | ], 23 | preprocessors: { 24 | './src/test.ts': ['@angular/cli'] 25 | }, 26 | coverageIstanbulReporter: { 27 | reports: ['html', 'lcovonly'], 28 | fixWebpackSourcePaths: true 29 | }, 30 | 31 | reporters: config.angularCli && config.angularCli.codeCoverage ? ['progress', 'coverage-istanbul'] : ['progress', 'kjhtml'], 32 | port: 9876, 33 | colors: true, 34 | logLevel: config.LOG_INFO, 35 | autoWatch: true, 36 | browsers: ['Chrome'], 37 | singleRun: false 38 | }); 39 | }; -------------------------------------------------------------------------------- /src/app/state-management/feature-toggles/feature-toggles.reducers.ts: -------------------------------------------------------------------------------- 1 | import { 2 | ADD_FEATURE_TOGGLE, 3 | LOAD_TOGGLES_SUCCESS, 4 | REMOVE_FEATURE_TOGGLE, 5 | UPDATE_FEATURE_TOGGLE 6 | } from './feature-toggles.actions'; 7 | import { Action } from '@ngrx/store'; 8 | 9 | export function featureToggles(featureTogglesState = [], action: Action) { 10 | let state: boolean, name: String; 11 | switch (action.type) { 12 | 13 | case LOAD_TOGGLES_SUCCESS: 14 | return [...action.payload]; 15 | 16 | case ADD_FEATURE_TOGGLE: 17 | ({ name } = action.payload); 18 | ({ state } = action.payload); 19 | return [...featureTogglesState, { name: name, state: state }]; 20 | 21 | case REMOVE_FEATURE_TOGGLE: 22 | ({ name } = action.payload); 23 | return featureTogglesState.filter((toggle) => { 24 | return toggle.name !== name; 25 | }); 26 | 27 | case UPDATE_FEATURE_TOGGLE: 28 | ({ name } = action.payload); 29 | ({ state } = action.payload); 30 | let index = featureTogglesState.map(toggle => toggle.name).indexOf(name); 31 | return [ 32 | ...featureTogglesState.slice(0, index), 33 | { ...featureTogglesState[index], name: name, state: state }, 34 | ...featureTogglesState.slice(index + 1) 35 | ]; 36 | 37 | default: { 38 | return featureTogglesState; 39 | } 40 | } 41 | }; 42 | 43 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_APPS } from './state-management/apps'; 2 | import { LOAD_APP } from './state-management/app'; 3 | import { Component, OnInit } from '@angular/core'; 4 | import { Store } from '@ngrx/store'; 5 | import { Observable } from 'rxjs/Rx'; 6 | import { App } from './state-management/app'; 7 | 8 | @Component({ 9 | selector: 'app-root', 10 | templateUrl: './app.component.html', 11 | styleUrls: ['./app.component.scss'] 12 | }) 13 | export class AppComponent implements OnInit { 14 | selectedApp$: Observable; 15 | selectedAppId: String; 16 | apps$: Observable>; 17 | 18 | constructor(private store: Store) { 19 | } 20 | 21 | ngOnInit(): void { 22 | this.selectedApp$ = this.store.select('app'); 23 | this.apps$ = this.store.select('apps'); 24 | this.store.select('app').subscribe((app: App) => { 25 | this.selectedAppId = app.id; 26 | }); 27 | //select and fetch the first app on the list 28 | this.store.select('apps').subscribe((apps: Array) => { 29 | if (apps.length) { 30 | this.store.dispatch({ 31 | type: LOAD_APP, 32 | payload: { 33 | id: apps[0].id 34 | } 35 | }); 36 | } 37 | }); 38 | //Load list of apps from API 39 | this.store.dispatch({ 40 | type: LOAD_APPS, 41 | payload: {} 42 | }); 43 | } 44 | 45 | loadApp(id: String) { 46 | if (id !== this.selectedAppId) { 47 | this.store.dispatch({ 48 | type: LOAD_APP, 49 | payload: { 50 | id: id 51 | } 52 | }); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/app/state-management/feature-toggles/feature-toggles.reducers.spec.ts: -------------------------------------------------------------------------------- 1 | import {ADD_FEATURE_TOGGLE, REMOVE_FEATURE_TOGGLE, UPDATE_FEATURE_TOGGLE} from '.'; 2 | import { featureToggles } from '.'; 3 | 4 | 5 | describe('feature-toggles reducer', () => { 6 | it('should return current state when no valid actions have been made', () => { 7 | const state = []; 8 | const actual = featureToggles(state, { type: 'INVALID_ACTION', payload: {} }); 9 | const expected = state; 10 | expect(actual).toBe(expected); 11 | }); 12 | 13 | it('should add a feature toggle', () => { 14 | const state = []; 15 | const actual = featureToggles(state, { type: ADD_FEATURE_TOGGLE, payload: {name: 'testToggle', state: false} }); 16 | const expected = {name: 'testToggle', state: false}; 17 | expect(actual).toContain(expected); 18 | }); 19 | 20 | it('should update a feature toggle', () => { 21 | const state = [{name: 'testToggle', state: true}]; 22 | const actual = featureToggles(state, { type: UPDATE_FEATURE_TOGGLE, payload: {name: 'testToggle', state: false} }); 23 | const expected = [{name: 'testToggle', state: false}]; 24 | expect(actual).toEqual(expected); 25 | }); 26 | 27 | it('should remove a feature toggle', () => { 28 | const state = [{name: 'testToggle', state: true}, {name: 'testToggle1', state: false}]; 29 | const actual = featureToggles(state, { type: REMOVE_FEATURE_TOGGLE, payload: {name: 'testToggle'} }); 30 | const expected = [{name: 'testToggle1', state: false}]; 31 | expect(actual).toEqual(expected); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 9 |
10 |
11 |
12 |
13 |

14 | {{ (selectedApp$ | async)?.name }} 15 |

16 | 17 | 21 | 24 | 25 |
26 | 27 | 28 | Feature Toggles 29 | Config Properties 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 |
-------------------------------------------------------------------------------- /angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.19-3", 4 | "name": "remote-config-dashboard" 5 | }, 6 | "apps": [{ 7 | "root": "src", 8 | "outDir": "dist", 9 | "assets": [ 10 | "assets", 11 | "favicon.ico" 12 | ], 13 | "index": "index.html", 14 | "main": "main.ts", 15 | "polyfills": "polyfills.ts", 16 | "test": "test.ts", 17 | "tsconfig": "tsconfig.json", 18 | "prefix": "app", 19 | "mobile": false, 20 | "styles": [ 21 | "styles.scss", 22 | "../node_modules/clarity-icons/clarity-icons.min.css", 23 | "../node_modules/clarity-ui/clarity-ui.min.css", 24 | "../node_modules/jsoneditor/dist/jsoneditor.min.css" 25 | ], 26 | "scripts": [ 27 | "../node_modules/mutationobserver-shim/dist/mutationobserver.min.js", 28 | "../node_modules/@webcomponents/custom-elements/custom-elements.min.js", 29 | "../node_modules/clarity-icons/clarity-icons.min.js", 30 | "../node_modules/jsoneditor/dist/jsoneditor.js" 31 | ], 32 | "environmentSource": "environments/environment.ts", 33 | "environments": { 34 | "dev": "environments/environment.ts", 35 | "prod": "environments/environment.prod.ts" 36 | } 37 | }], 38 | "addons": [], 39 | "packages": [], 40 | "e2e": { 41 | "protractor": { 42 | "config": "./protractor.conf.js" 43 | } 44 | }, 45 | "test": { 46 | "karma": { 47 | "config": "./karma.conf.js" 48 | } 49 | }, 50 | "defaults": { 51 | "styleExt": "scss", 52 | "prefixInterfaces": false, 53 | "inline": { 54 | "style": false, 55 | "template": false 56 | }, 57 | "spec": { 58 | "class": false, 59 | "component": true, 60 | "directive": true, 61 | "module": false, 62 | "pipe": true, 63 | "service": true 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { AppEffects } from './state-management/app'; 2 | import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; 3 | import { app } from './state-management/app'; 4 | import { apps } from './state-management/apps'; 5 | import { properties } from './state-management/properties'; 6 | import { featureToggles } from './state-management/feature-toggles'; 7 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 8 | import { BrowserModule} from '@angular/platform-browser'; 9 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 10 | import { NgModule, } from '@angular/core'; 11 | import { FormsModule } from '@angular/forms'; 12 | import { HttpModule } from '@angular/http'; 13 | import { ClarityModule } from 'clarity-angular'; 14 | import { AppComponent } from './app.component'; 15 | import { StoreModule } from '@ngrx/store'; 16 | import { FeatureTogglesComponent } from './feature-toggles/feature-toggles.component'; 17 | import { ReactiveFormsModule } from '@angular/forms'; 18 | import { ConfigPropertiesComponent } from './config-properties/config-properties.component'; 19 | import { EffectsModule } from '@ngrx/effects'; 20 | import { AppsEffects } from './state-management/apps'; 21 | import { FilterPipe } from './shared/pipes/filter.pipe'; 22 | import { AddToggleModalComponent } from './add-toggle-modal/add-toggle-modal.component'; 23 | 24 | @NgModule({ 25 | declarations: [ 26 | AppComponent, 27 | FeatureTogglesComponent, 28 | ConfigPropertiesComponent, 29 | FilterPipe, 30 | AddToggleModalComponent 31 | ], 32 | imports: [ 33 | BrowserModule, 34 | FormsModule, 35 | HttpModule, 36 | ClarityModule.forChild(), 37 | StoreModule.provideStore({featureToggles, properties, apps, app}), 38 | StoreDevtoolsModule.instrumentOnlyWithExtension({ 39 | maxAge: 5 40 | }), 41 | ReactiveFormsModule, 42 | BrowserAnimationsModule, 43 | EffectsModule.run(AppsEffects), 44 | EffectsModule.run(AppEffects) 45 | ], 46 | providers: [FilterPipe], 47 | bootstrap: [AppComponent], 48 | schemas: [ 49 | CUSTOM_ELEMENTS_SCHEMA 50 | ], 51 | }) 52 | export class AppModule { } 53 | -------------------------------------------------------------------------------- /src/app/feature-toggles/feature-toggles.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 32 | 33 |
5 | 6 | 9 | 13 |
{{toggle.name}} 20 |
21 | 22 | 23 |
24 |
26 | 30 |
34 | 35 | 36 | 37 | 38 | 41 | 45 | -------------------------------------------------------------------------------- /src/app/feature-toggles/feature-toggles.component.ts: -------------------------------------------------------------------------------- 1 | import { AddToggleModalComponent } from '../add-toggle-modal/add-toggle-modal.component'; 2 | import { FeatureToggle } from '../state-management/feature-toggles'; 3 | import { Store } from '@ngrx/store'; 4 | import { Observable } from 'rxjs/Rx'; 5 | import { Component, OnInit, ViewChild } from '@angular/core'; 6 | import { ADD_FEATURE_TOGGLE, UPDATE_FEATURE_TOGGLE, REMOVE_FEATURE_TOGGLE } from '../state-management/feature-toggles'; 7 | 8 | @Component({ 9 | selector: 'app-feature-toggles', 10 | templateUrl: './feature-toggles.component.html', 11 | styleUrls: ['./feature-toggles.component.scss'] 12 | }) 13 | export class FeatureTogglesComponent implements OnInit { 14 | 15 | @ViewChild(AddToggleModalComponent) addToggleModal: AddToggleModalComponent 16 | 17 | featureToggles$: Observable>; 18 | isConfirmationModalOpen = false; 19 | selectedToggleName: String; 20 | confirmationMessage: String; 21 | 22 | constructor(private store: Store) { 23 | this.featureToggles$ = this.store.select('featureToggles'); 24 | } 25 | 26 | ngOnInit() { 27 | } 28 | 29 | ngAfterViewInit() { 30 | //pass array of toggles to add modal, to check if a toggle already exists before adding 31 | this.featureToggles$.subscribe((toggles) => { 32 | this.addToggleModal.featureToggles = toggles; 33 | }); 34 | } 35 | 36 | openRemovalConfirmationModal(name: String) { 37 | this.selectedToggleName = name; 38 | this.confirmationMessage = `Are you sure you want to remove the toggle ${name}?`; 39 | this.isConfirmationModalOpen = true; 40 | } 41 | 42 | confirmToggleRemoval() { 43 | this.isConfirmationModalOpen = false; 44 | this.removeFeatureToggle(this.selectedToggleName) 45 | } 46 | 47 | updateFeatureToggle(name: String, state: boolean) { 48 | this.store.dispatch({ 49 | type: UPDATE_FEATURE_TOGGLE, 50 | payload: 51 | { 52 | name: name, 53 | state: state 54 | } 55 | }); 56 | } 57 | 58 | removeFeatureToggle(name: String) { 59 | this.store.dispatch({ 60 | type: REMOVE_FEATURE_TOGGLE, 61 | payload: 62 | { 63 | name: name 64 | } 65 | }); 66 | } 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/app/add-toggle-modal/add-toggle-modal.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | 40 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "remote-config-dashboard", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "start": "ng serve", 8 | "lint": "tslint \"src/**/*.ts\"", 9 | "test": "ng test", 10 | "pree2e": "webdriver-manager update", 11 | "e2e": "protractor" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "~4.0.1", 16 | "@angular/common": "~4.0.1", 17 | "@angular/compiler": "~4.0.1", 18 | "@angular/core": "~4.0.1", 19 | "@angular/forms": "~4.0.1", 20 | "@angular/http": "~4.0.1", 21 | "@angular/platform-browser": "~4.0.1", 22 | "@angular/platform-browser-dynamic": "~4.0.1", 23 | "@angular/router": "~4.0.1", 24 | "@ngrx/core": "^1.2.0", 25 | "@ngrx/effects": "^2.0.2", 26 | "@ngrx/store": "^2.2.1", 27 | "@ngrx/store-devtools": "^3.2.3", 28 | "@webcomponents/custom-elements": "^1.0.0-alpha.3", 29 | "ajv": "5.0.1-beta.3", 30 | "clarity-angular": "^0.9.3", 31 | "clarity-icons": "^0.9.3", 32 | "clarity-ui": "^0.9.3", 33 | "core-js": "^2.4.1", 34 | "jsoneditor": "^5.5.11", 35 | "karma-coverage-istanbul-reporter": "^1.2.0", 36 | "karma-jasmine-html-reporter": "^0.2.2", 37 | "mutationobserver-shim": "^0.3.2", 38 | "ngrx-domains": "^1.0.0-alpha.4", 39 | "rxjs": "5.1.0", 40 | "ts-helpers": "^1.1.1", 41 | "zone.js": "^0.8.4" 42 | }, 43 | "devDependencies": { 44 | "@angular/cli": "1.0.0", 45 | "@angular/compiler-cli": "^4.0.1", 46 | "@types/jasmine": "^2.2.30", 47 | "@types/jsoneditor": "^5.5.2", 48 | "@types/node": "^6.0.60", 49 | "codelyzer": "1.0.0-beta.1", 50 | "jasmine-core": "2.4.1", 51 | "jasmine-spec-reporter": "2.5.0", 52 | "karma": "1.2.0", 53 | "karma-chrome-launcher": "^2.0.0", 54 | "karma-cli": "^1.0.1", 55 | "karma-jasmine": "^1.0.2", 56 | "karma-remap-istanbul": "^0.2.1", 57 | "karma-teamcity-reporter": "^1.0.0", 58 | "protractor": "4.0.9", 59 | "ts-node": "1.2.1", 60 | "tslint": "3.13.0", 61 | "typescript": "~2.2.0", 62 | "webdriver-manager": "10.2.5" 63 | } 64 | } -------------------------------------------------------------------------------- /src/app/add-toggle-modal/add-toggle-modal.component.ts: -------------------------------------------------------------------------------- 1 | import { ViewChild } from '@angular/core'; 2 | import { Store } from '@ngrx/store'; 3 | import { ADD_FEATURE_TOGGLE, FeatureToggle, featureToggles } from '../state-management/feature-toggles'; 4 | import { Component, OnInit } from '@angular/core'; 5 | import { FormGroup, FormControl, Validators, FormBuilder } from '@angular/forms'; 6 | import { ChangeDetectorRef } from '@angular/core'; 7 | 8 | @Component({ 9 | selector: 'add-toggle-modal', 10 | templateUrl: './add-toggle-modal.component.html', 11 | styleUrls: ['./add-toggle-modal.component.scss'] 12 | }) 13 | export class AddToggleModalComponent implements OnInit { 14 | featureToggleForm: any; 15 | submitted = false; 16 | isAddToggleModalOpen = false; 17 | showToggleExistsWarning = false; 18 | featureToggles: FeatureToggle[]; 19 | 20 | @ViewChild('toggleName') toggleNameInput; 21 | 22 | constructor(private fb: FormBuilder, private store: Store, private cdRef : ChangeDetectorRef) { } 23 | 24 | ngOnInit() { 25 | this.featureToggleForm = this.fb.group({ 26 | toggleName: new FormControl('', Validators.required), 27 | toggleState: new FormGroup({ 28 | state: new FormControl('') 29 | }) 30 | }); 31 | } 32 | 33 | 34 | openAddToggleModal() { 35 | this.featureToggleForm.reset(); 36 | this.showToggleExistsWarning = false; 37 | this.submitted = false; 38 | this.isAddToggleModalOpen = true; 39 | setTimeout(() => { 40 | this.toggleNameInput.nativeElement.focus(); 41 | }, 0); 42 | 43 | } 44 | 45 | addToggleClicked() { 46 | this.showToggleExistsWarning = false; 47 | let formData = this.featureToggleForm.value; 48 | 49 | if (this.doesToggleAlreadyExist(formData.toggleName)) { 50 | this.showToggleExistsWarning = true; 51 | } else { 52 | this.isAddToggleModalOpen = false; 53 | this.cdRef.detectChanges(); 54 | this.addFeatureToggle({ 55 | name: formData.toggleName, 56 | state: !!formData.toggleState.state 57 | }) 58 | } 59 | } 60 | doesToggleAlreadyExist(name) { 61 | return this.featureToggles.filter((toggle) => toggle.name === name).length; 62 | } 63 | 64 | addFeatureToggle(toggle: FeatureToggle) { 65 | this.store.dispatch({ 66 | type: ADD_FEATURE_TOGGLE, 67 | payload: {...toggle} 68 | }); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Remote Config Dashboard 2 | [![Build Status](https://travis-ci.org/joaoflf/remote-config-dashboard.svg?branch=master)](https://travis-ci.org/joaoflf/remote-config-dashboard) 3 | 4 | Angular Dashboard to manage feature toggles and remote configuration. 5 | 6 | ## About 7 | Feature toggles are becoming a necessity for organizations that wish to release in a continuous fashion. They allow for the decoupling of technical and product releases, rapid failover recovery and if extended even cool stuff like A/B testing. 8 | There are some great commercial options to respond to this need. However, for a simple implementation a basic service with a list of toggles and their states would suffice. 9 | 10 | This project was born out of the necessity for such simple implementation. 11 | It comprises of a web interface to manage feature toggles and other configurable remote properties that one might need in a web or native mobile app. This web app is meant to be plugged to an web service that would return app configuration, allow to post new configuration, etc. 12 | 13 | It is meant to be open to be modified in order to suit different needs. 14 | 15 | Check out a live demo [here](https://joaoflf.github.io/remote-config-dashboard/). 16 | 17 |

18 | 19 | ## App & State Management 20 | This web app is built using Angular 4 with the [angular-cli](https://github.com/angular/angular-cli). 21 | It also uses [ngrx](https://github.com/ngrx) to manage its state, so you can use [redux-devtools-extension](https://github.com/zalmoxisus/redux-devtools-extension) to inspect it. 22 | The idea is for the app to manage all its state offline and when the user wishes, he can press a *publish* button to synchronize the config json with the service. 23 | [ngrx/effects](https://github.com/ngrx/effects) used to connect to a mock api for fetching data. 24 | 25 | A [Remote Config API](https://github.com/joaoflf/remote-config-api) is also being built to support the web app. 26 | 27 | ## Development 28 | Run `npm start` to launch the web server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 29 | The web app is using a mock api provided by mockable.io 30 | 31 | ## Next steps 32 | * Sync Button 33 | * Loading States 34 | 35 | ## Credits 36 | In order to build this dashboard, some amazing open source projects and components were used. These include [ngrx](https://github.com/ngrx), [ClarityUI](https://vmware.github.io/clarity/) and [JSONEditor](https://github.com/josdejong/jsoneditor) 37 | 38 | -------------------------------------------------------------------------------- /src/app/feature-toggles/feature-toggles.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_TOGGLES_SUCCESS } from '../state-management/feature-toggles'; 2 | import { Store } from '@ngrx/store'; 3 | import { AppModule } from '../'; 4 | /* tslint:disable:no-unused-variable */ 5 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 6 | import { By } from '@angular/platform-browser'; 7 | import { FeatureTogglesComponent } from './feature-toggles.component'; 8 | 9 | describe('FeatureTogglesComponent', () => { 10 | let component: FeatureTogglesComponent; 11 | let fixture: ComponentFixture; 12 | 13 | beforeEach(async(() => { 14 | TestBed.configureTestingModule({ 15 | imports: [AppModule] 16 | }) 17 | .compileComponents() 18 | .then(() => { 19 | fixture = TestBed.createComponent(FeatureTogglesComponent); 20 | let store = fixture.debugElement.injector.get(Store); 21 | store.dispatch({ 22 | type: LOAD_TOGGLES_SUCCESS, 23 | payload: [ 24 | { 25 | name: 'testToggle', 26 | state: false 27 | } 28 | ] 29 | }); 30 | component = fixture.componentInstance; 31 | fixture.detectChanges(); 32 | }); 33 | })); 34 | 35 | it('should create the component and view elements', () => { 36 | expect(component).toBeTruthy(); 37 | let element = fixture.nativeElement; 38 | expect(element.querySelector('.toggles-table')).toBeTruthy(); 39 | expect(element.querySelector('.toggle-search-input')).toBeTruthy(); 40 | expect(element.querySelector('.new-toggle-button')).toBeTruthy(); 41 | }); 42 | 43 | it('should get featureToggles from store and render them in the table', () => { 44 | component.featureToggles$.subscribe((toggles) => { 45 | expect(toggles[0].name).toBe('testToggle'); 46 | }); 47 | 48 | let element = fixture.nativeElement; 49 | expect(element.querySelector('.toggle-name-cell').innerHTML).toBe('testToggle'); 50 | }); 51 | 52 | it('should remove a toggle with confirmation modal', () => { 53 | component.openRemovalConfirmationModal('testToggle'); 54 | expect(component.confirmationMessage).toBe('Are you sure you want to remove the toggle testToggle?'); 55 | expect(component.isConfirmationModalOpen).toBeTruthy(); 56 | 57 | component.confirmToggleRemoval(); 58 | component.featureToggles$.subscribe((toggles) => { 59 | expect(toggles.length).toBe(0); 60 | }); 61 | }); 62 | 63 | it('should update a toggle', () => { 64 | component.updateFeatureToggle('testToggle', true); 65 | component.featureToggles$.subscribe((toggles) => { 66 | expect(toggles[0].state).toBeTruthy(); 67 | }); 68 | }); 69 | }); 70 | -------------------------------------------------------------------------------- /src/app/config-properties/config-properties.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_PROPERTIES_SUCCESS, UPDATE_PROPERTIES } from '../state-management/properties'; 2 | import { Store } from '@ngrx/store'; 3 | import { AppModule } from '../'; 4 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 5 | import { ConfigPropertiesComponent } from './config-properties.component'; 6 | 7 | describe('ConfigPropertiesComponent', () => { 8 | let component: ConfigPropertiesComponent; 9 | let fixture: ComponentFixture; 10 | let store: Store; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | imports: [AppModule] 15 | }) 16 | .compileComponents() 17 | .then(() => { 18 | fixture = TestBed.createComponent(ConfigPropertiesComponent); 19 | component = fixture.componentInstance; 20 | store = fixture.debugElement.injector.get(Store); 21 | }); 22 | })); 23 | 24 | it('should create the component', () => { 25 | expect(component).toBeTruthy(); 26 | }); 27 | 28 | it('should create the json editor component with the loaded properties', () => { 29 | component.ngAfterViewInit(); 30 | store.dispatch({ 31 | type: LOAD_PROPERTIES_SUCCESS, 32 | payload: { 33 | testProperty: 'test' 34 | } 35 | }); 36 | expect(component.editor).toBeTruthy(); 37 | expect(fixture.nativeElement.querySelector('.jsoneditor-field').innerHTML).toBe('testProperty'); 38 | expect(fixture.nativeElement.querySelector('.jsoneditor-string').innerHTML).toBe('test'); 39 | }); 40 | 41 | it('should dispatch an action to store when editor changes', () => { 42 | let dispatchAction = spyOn(store, 'dispatch').and.callThrough(); 43 | component.ngAfterViewInit(); 44 | store.dispatch({ 45 | type: LOAD_PROPERTIES_SUCCESS, 46 | payload: { 47 | testProperty: 'test' 48 | } 49 | }); 50 | component.onJsonEditorChange(); 51 | expect(dispatchAction).toHaveBeenCalledWith({ 52 | type: UPDATE_PROPERTIES, 53 | payload: { 54 | testProperty: 'test' 55 | } 56 | }); 57 | }); 58 | 59 | it('should update the json editor component with the changed properties', () => { 60 | component.ngAfterViewInit(); 61 | store.dispatch({ 62 | type: LOAD_PROPERTIES_SUCCESS, 63 | payload: { 64 | testProperty: 'test' 65 | } 66 | }); 67 | let updateEditor = spyOn(component.editor, 'set').and.callThrough(); 68 | store.dispatch({ 69 | type: UPDATE_PROPERTIES, 70 | payload: { 71 | testProperty: 'test2' 72 | } 73 | }); 74 | expect(updateEditor).toHaveBeenCalledWith({ 75 | testProperty: 'test2' 76 | }); 77 | }); 78 | }); 79 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { LOAD_APPS, LOAD_APPS_SUCCESS } from './state-management/apps'; 2 | import { App, LOAD_APP, LOAD_APP_SUCCESS } from './state-management/app'; 3 | import { Store } from '@ngrx/store'; 4 | import { ComponentFixture } from '@angular/core/testing/src/testing'; 5 | import { AppModule } from './'; 6 | /* tslint:disable:no-unused-variable */ 7 | import { TestBed, async } from '@angular/core/testing'; 8 | import { AppComponent } from './app.component'; 9 | 10 | describe('App: RemoteConfigDashboard', () => { 11 | 12 | let component: AppComponent; 13 | let fixture: ComponentFixture; 14 | let store: Store; 15 | 16 | beforeEach(async(() => { 17 | TestBed.configureTestingModule({ 18 | imports: [ 19 | AppModule 20 | ] 21 | }).compileComponents() 22 | .then(() => { 23 | fixture = TestBed.createComponent(AppComponent); 24 | component = fixture.debugElement.componentInstance; 25 | store = fixture.debugElement.injector.get(Store); 26 | }); 27 | })); 28 | 29 | it('should create the app', async(() => { 30 | expect(component).toBeTruthy(); 31 | })); 32 | 33 | it('should dispatch actions to load the list of apps', async(() => { 34 | let dispatchCall = spyOn(store, 'dispatch').and.callThrough(); 35 | component.ngOnInit(); 36 | expect(dispatchCall).toHaveBeenCalledWith({ 37 | type: LOAD_APPS, 38 | payload: {} 39 | }); 40 | })); 41 | 42 | it('should dispatch actions to load the first app when receiving list of apps', async(() => { 43 | let dispatchCall = spyOn(store, 'dispatch').and.callThrough(); 44 | store.dispatch({ 45 | type: LOAD_APPS_SUCCESS, 46 | payload: [{ 47 | id: '1' 48 | }] 49 | }); 50 | component.ngOnInit(); 51 | expect(dispatchCall).toHaveBeenCalledWith({ 52 | type: LOAD_APP, 53 | payload: { 54 | id: '1' 55 | } 56 | }); 57 | store.dispatch({ 58 | type: LOAD_APP_SUCCESS, 59 | payload: [{ 60 | id: '1', 61 | name: 'Web App' 62 | }] 63 | }); 64 | })); 65 | it('should dispatch actions to load another app when selected', async(() => { 66 | let dispatchCall = spyOn(store, 'dispatch').and.callThrough(); 67 | store.dispatch({ 68 | type: LOAD_APPS_SUCCESS, 69 | payload: [{ 70 | id: '1' 71 | }] 72 | }); 73 | component.ngOnInit(); 74 | store.dispatch({ 75 | type: LOAD_APP_SUCCESS, 76 | payload: [{ 77 | id: '1', 78 | name: 'Web App' 79 | }] 80 | }); 81 | component.loadApp('2'); 82 | expect(dispatchCall).toHaveBeenCalledWith({ 83 | type: LOAD_APP, 84 | payload: { 85 | id: '2' 86 | } 87 | }); 88 | })); 89 | }); 90 | -------------------------------------------------------------------------------- /src/app/add-toggle-modal/add-toggle-modal.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ADD_FEATURE_TOGGLE } from '../state-management/feature-toggles'; 2 | import { Store } from '@ngrx/store'; 3 | import { AppModule } from '../'; 4 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 5 | import { AddToggleModalComponent } from './add-toggle-modal.component'; 6 | 7 | describe('AddToggleModalComponent', () => { 8 | let component: AddToggleModalComponent; 9 | let fixture: ComponentFixture; 10 | let store; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | imports: [AppModule] 15 | }) 16 | .compileComponents() 17 | .then(() => { 18 | fixture = TestBed.createComponent(AddToggleModalComponent); 19 | component = fixture.componentInstance; 20 | fixture.detectChanges(); 21 | store = fixture.debugElement.injector.get(Store); 22 | }); 23 | })); 24 | 25 | it('should create the component', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | 29 | it('should open the modal on a blank state', () => { 30 | let resetForm = spyOn(component.featureToggleForm, 'reset').and.callThrough(); 31 | component.openAddToggleModal(); 32 | fixture.detectChanges(); 33 | expect(component.showToggleExistsWarning).toBeFalsy(); 34 | expect(component.submitted).toBeFalsy(); 35 | expect(component.isAddToggleModalOpen).toBeTruthy(); 36 | expect(resetForm).toHaveBeenCalled(); 37 | let element = fixture.nativeElement; 38 | expect(element.querySelector('.modal-dialog')).toBeTruthy(); 39 | }); 40 | 41 | it('should add a toggle', () => { 42 | let dispatchAction = spyOn(store, 'dispatch').and.callThrough(); 43 | component.featureToggles = []; 44 | component.openAddToggleModal(); 45 | fixture.detectChanges(); 46 | component.featureToggleForm.controls['toggleName'].setValue('testToggle'); 47 | component.addToggleClicked(); 48 | fixture.detectChanges(); 49 | 50 | expect(dispatchAction).toHaveBeenCalledWith({ 51 | type: ADD_FEATURE_TOGGLE, 52 | payload: { 53 | name: 'testToggle', 54 | state: false 55 | } 56 | }); 57 | expect(component.isAddToggleModalOpen).toBeFalsy(); 58 | }); 59 | 60 | it('should not add a toggle if it already exists', () => { 61 | component.featureToggles = [{ 62 | name: 'testToggle', 63 | state: false 64 | }]; 65 | component.openAddToggleModal(); 66 | fixture.detectChanges(); 67 | component.featureToggleForm.controls['toggleName'].setValue('testToggle'); 68 | component.addToggleClicked(); 69 | fixture.detectChanges(); 70 | 71 | expect(component.isAddToggleModalOpen).toBeTruthy(); 72 | expect(component.showToggleExistsWarning).toBeTruthy(); 73 | expect(fixture.nativeElement.querySelector('.toggle-exists-alert')).toBeTruthy(); 74 | }); 75 | }); 76 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "class-name": true, 7 | "comment-format": [ 8 | true, 9 | "check-space" 10 | ], 11 | "curly": true, 12 | "eofline": true, 13 | "forin": true, 14 | "indent": [ 15 | true, 16 | "spaces" 17 | ], 18 | "label-position": true, 19 | "label-undefined": true, 20 | "max-line-length": [ 21 | true, 22 | 140 23 | ], 24 | "member-access": false, 25 | "member-ordering": [ 26 | true, 27 | "static-before-instance", 28 | "variables-before-functions" 29 | ], 30 | "no-arg": true, 31 | "no-bitwise": true, 32 | "no-console": [ 33 | true, 34 | "debug", 35 | "info", 36 | "time", 37 | "timeEnd", 38 | "trace" 39 | ], 40 | "no-construct": true, 41 | "no-debugger": true, 42 | "no-duplicate-key": true, 43 | "no-duplicate-variable": true, 44 | "no-empty": false, 45 | "no-eval": true, 46 | "no-inferrable-types": true, 47 | "no-shadowed-variable": true, 48 | "no-string-literal": false, 49 | "no-switch-case-fall-through": true, 50 | "no-trailing-whitespace": true, 51 | "no-unused-expression": true, 52 | "no-unused-variable": true, 53 | "no-unreachable": true, 54 | "no-use-before-declare": true, 55 | "no-var-keyword": true, 56 | "object-literal-sort-keys": false, 57 | "one-line": [ 58 | true, 59 | "check-open-brace", 60 | "check-catch", 61 | "check-else", 62 | "check-whitespace" 63 | ], 64 | "quotemark": [ 65 | true, 66 | "single" 67 | ], 68 | "radix": true, 69 | "semicolon": [ 70 | "always" 71 | ], 72 | "triple-equals": [ 73 | true, 74 | "allow-null-check" 75 | ], 76 | "typedef-whitespace": [ 77 | true, 78 | { 79 | "call-signature": "nospace", 80 | "index-signature": "nospace", 81 | "parameter": "nospace", 82 | "property-declaration": "nospace", 83 | "variable-declaration": "nospace" 84 | } 85 | ], 86 | "variable-name": false, 87 | "whitespace": [ 88 | true, 89 | "check-branch", 90 | "check-decl", 91 | "check-operator", 92 | "check-separator", 93 | "check-type" 94 | ], 95 | 96 | "directive-selector-prefix": [true, "app"], 97 | "component-selector-prefix": [true, "app"], 98 | "directive-selector-name": [true, "camelCase"], 99 | "component-selector-name": [true, "kebab-case"], 100 | "directive-selector-type": [true, "attribute"], 101 | "component-selector-type": [true, "element"], 102 | "use-input-property-decorator": true, 103 | "use-output-property-decorator": true, 104 | "use-host-property-decorator": true, 105 | "no-input-rename": true, 106 | "no-output-rename": true, 107 | "use-life-cycle-interface": true, 108 | "use-pipe-transform-interface": true, 109 | "component-class-suffix": true, 110 | "directive-class-suffix": true, 111 | "templates-use-public": true, 112 | "invoke-injectable": true 113 | } 114 | } 115 | --------------------------------------------------------------------------------