├── .editorconfig ├── .github ├── FUNDING.yml └── workflows │ ├── deploy-demo.yml │ └── publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── angular.json ├── package-lock.json ├── package.json ├── projects ├── demo │ ├── browserslist │ ├── e2e │ │ ├── protractor.conf.js │ │ ├── src │ │ │ ├── app.e2e-spec.ts │ │ │ └── app.po.ts │ │ └── tsconfig.json │ ├── karma.conf.js │ ├── src │ │ ├── .nojekyll │ │ ├── app │ │ │ ├── app-routing.module.ts │ │ │ ├── app.component.css │ │ │ ├── app.component.html │ │ │ ├── app.component.spec.ts │ │ │ ├── app.component.ts │ │ │ └── app.module.ts │ │ ├── assets │ │ │ ├── .gitkeep │ │ │ └── images │ │ │ │ └── logo.svg │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main.ts │ │ ├── polyfills.ts │ │ ├── styles.css │ │ └── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json └── fire-admin │ ├── README.md │ ├── karma.conf.js │ ├── ng-package.json │ ├── package.json │ ├── src │ ├── lib │ │ ├── components │ │ │ ├── dashboard │ │ │ │ ├── dashboard.component.css │ │ │ │ ├── dashboard.component.html │ │ │ │ ├── dashboard.component.spec.ts │ │ │ │ └── dashboard.component.ts │ │ │ ├── login │ │ │ │ ├── login.component.css │ │ │ │ ├── login.component.html │ │ │ │ ├── login.component.spec.ts │ │ │ │ └── login.component.ts │ │ │ ├── logout │ │ │ │ ├── logout.component.css │ │ │ │ ├── logout.component.html │ │ │ │ ├── logout.component.spec.ts │ │ │ │ └── logout.component.ts │ │ │ ├── pages │ │ │ │ ├── add │ │ │ │ │ ├── pages-add.component.css │ │ │ │ │ ├── pages-add.component.html │ │ │ │ │ ├── pages-add.component.spec.ts │ │ │ │ │ └── pages-add.component.ts │ │ │ │ ├── edit │ │ │ │ │ ├── pages-edit.component.css │ │ │ │ │ ├── pages-edit.component.html │ │ │ │ │ ├── pages-edit.component.spec.ts │ │ │ │ │ └── pages-edit.component.ts │ │ │ │ ├── list │ │ │ │ │ ├── pages-list.component.css │ │ │ │ │ ├── pages-list.component.html │ │ │ │ │ ├── pages-list.component.spec.ts │ │ │ │ │ └── pages-list.component.ts │ │ │ │ └── translate │ │ │ │ │ ├── pages-translate.component.css │ │ │ │ │ ├── pages-translate.component.html │ │ │ │ │ ├── pages-translate.component.spec.ts │ │ │ │ │ └── pages-translate.component.ts │ │ │ ├── posts │ │ │ │ ├── add │ │ │ │ │ ├── posts-add.component.css │ │ │ │ │ ├── posts-add.component.html │ │ │ │ │ ├── posts-add.component.spec.ts │ │ │ │ │ └── posts-add.component.ts │ │ │ │ ├── categories │ │ │ │ │ ├── posts-categories.component.css │ │ │ │ │ ├── posts-categories.component.html │ │ │ │ │ ├── posts-categories.component.spec.ts │ │ │ │ │ └── posts-categories.component.ts │ │ │ │ ├── edit │ │ │ │ │ ├── posts-edit.component.css │ │ │ │ │ ├── posts-edit.component.html │ │ │ │ │ ├── posts-edit.component.spec.ts │ │ │ │ │ └── posts-edit.component.ts │ │ │ │ ├── list │ │ │ │ │ ├── posts-list.component.css │ │ │ │ │ ├── posts-list.component.html │ │ │ │ │ ├── posts-list.component.spec.ts │ │ │ │ │ └── posts-list.component.ts │ │ │ │ └── translate │ │ │ │ │ ├── posts-translate.component.css │ │ │ │ │ ├── posts-translate.component.html │ │ │ │ │ ├── posts-translate.component.spec.ts │ │ │ │ │ └── posts-translate.component.ts │ │ │ ├── register │ │ │ │ ├── register.component.css │ │ │ │ ├── register.component.html │ │ │ │ ├── register.component.spec.ts │ │ │ │ └── register.component.ts │ │ │ ├── settings │ │ │ │ ├── settings.component.css │ │ │ │ ├── settings.component.html │ │ │ │ ├── settings.component.spec.ts │ │ │ │ └── settings.component.ts │ │ │ ├── shared │ │ │ │ ├── alert │ │ │ │ │ ├── alert.component.css │ │ │ │ │ ├── alert.component.html │ │ │ │ │ ├── alert.component.spec.ts │ │ │ │ │ └── alert.component.ts │ │ │ │ ├── button-group │ │ │ │ │ ├── button-group.component.css │ │ │ │ │ ├── button-group.component.html │ │ │ │ │ ├── button-group.component.spec.ts │ │ │ │ │ └── button-group.component.ts │ │ │ │ ├── footer │ │ │ │ │ ├── footer.component.css │ │ │ │ │ ├── footer.component.html │ │ │ │ │ ├── footer.component.spec.ts │ │ │ │ │ └── footer.component.ts │ │ │ │ ├── layout │ │ │ │ │ ├── layout.component.css │ │ │ │ │ ├── layout.component.html │ │ │ │ │ ├── layout.component.spec.ts │ │ │ │ │ └── layout.component.ts │ │ │ │ ├── loading-indicator │ │ │ │ │ ├── loading-indicator.component.css │ │ │ │ │ ├── loading-indicator.component.html │ │ │ │ │ ├── loading-indicator.component.spec.ts │ │ │ │ │ └── loading-indicator.component.ts │ │ │ │ ├── navbar │ │ │ │ │ ├── navbar.component.css │ │ │ │ │ ├── navbar.component.html │ │ │ │ │ ├── navbar.component.spec.ts │ │ │ │ │ └── navbar.component.ts │ │ │ │ └── sidebar │ │ │ │ │ ├── sidebar.component.css │ │ │ │ │ ├── sidebar.component.html │ │ │ │ │ ├── sidebar.component.spec.ts │ │ │ │ │ └── sidebar.component.ts │ │ │ ├── translations │ │ │ │ ├── translations.component.css │ │ │ │ ├── translations.component.html │ │ │ │ ├── translations.component.spec.ts │ │ │ │ └── translations.component.ts │ │ │ └── users │ │ │ │ ├── add │ │ │ │ ├── users-add.component.css │ │ │ │ ├── users-add.component.html │ │ │ │ ├── users-add.component.spec.ts │ │ │ │ └── users-add.component.ts │ │ │ │ ├── edit │ │ │ │ ├── users-edit.component.css │ │ │ │ ├── users-edit.component.html │ │ │ │ ├── users-edit.component.spec.ts │ │ │ │ └── users-edit.component.ts │ │ │ │ ├── list │ │ │ │ ├── users-list.component.css │ │ │ │ ├── users-list.component.html │ │ │ │ ├── users-list.component.spec.ts │ │ │ │ └── users-list.component.ts │ │ │ │ └── profile │ │ │ │ ├── users-profile.component.css │ │ │ │ ├── users-profile.component.html │ │ │ │ ├── users-profile.component.spec.ts │ │ │ │ └── users-profile.component.ts │ │ ├── fire-admin-routing.module.ts │ │ ├── fire-admin.component.css │ │ ├── fire-admin.component.spec.ts │ │ ├── fire-admin.component.ts │ │ ├── fire-admin.module.ts │ │ ├── fire-admin.service.spec.ts │ │ ├── fire-admin.service.ts │ │ ├── guards │ │ │ ├── auth.guard.ts │ │ │ ├── login.guard.ts │ │ │ ├── register.guard.ts │ │ │ └── user.guard.ts │ │ ├── helpers │ │ │ ├── assets.helper.ts │ │ │ ├── charts.helper.ts │ │ │ ├── datatables.helper.ts │ │ │ ├── functions.helper.ts │ │ │ ├── layout.helper.ts │ │ │ ├── posts.helper.ts │ │ │ └── timestamp.helper.ts │ │ ├── i18n │ │ │ ├── en.ts │ │ │ └── fr.ts │ │ ├── models │ │ │ ├── alert-type.model.ts │ │ │ ├── collections │ │ │ │ ├── category.model.ts │ │ │ │ ├── document-translation.ts │ │ │ │ ├── menu.model.ts │ │ │ │ ├── page.model.ts │ │ │ │ ├── post.model.ts │ │ │ │ ├── translation.model.ts │ │ │ │ └── user.model.ts │ │ │ ├── language.model.ts │ │ │ ├── settings.model.ts │ │ │ └── sidebar-item.model.ts │ │ ├── pipes │ │ │ ├── datetime.pipe.ts │ │ │ ├── escape-url.pipe.ts │ │ │ ├── shortdate.pipe.ts │ │ │ ├── timestamp.pipe.ts │ │ │ └── translate.pipe.ts │ │ └── services │ │ │ ├── alert.service.ts │ │ │ ├── auth.service.ts │ │ │ ├── collections │ │ │ ├── abstract │ │ │ │ └── document-translations.service.ts │ │ │ ├── categories.service.ts │ │ │ ├── config.service.ts │ │ │ ├── pages.service.ts │ │ │ ├── posts.service.ts │ │ │ ├── translations.service.ts │ │ │ └── users.service.ts │ │ │ ├── current-user.service.ts │ │ │ ├── database.service.ts │ │ │ ├── firebase-user.service.ts │ │ │ ├── i18n.service.ts │ │ │ ├── local-storage.service.ts │ │ │ ├── navigation.service.ts │ │ │ ├── settings.service.ts │ │ │ └── storage.service.ts │ ├── public-api.ts │ └── test.ts │ ├── tsconfig.lib.json │ ├── tsconfig.spec.json │ └── tslint.json ├── screenshots ├── dashboard.png └── user-profile.png ├── tsconfig.json └── tslint.json /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://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 = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: https://www.paypal.me/axeldev 13 | -------------------------------------------------------------------------------- /.github/workflows/deploy-demo.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy Demo 2 | on: 3 | push: 4 | tags: 5 | - 'v*.*.*' 6 | - 'deploy-demo' 7 | jobs: 8 | build-and-deploy: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 🛎️ 12 | uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. 13 | with: 14 | persist-credentials: false 15 | 16 | - name: Install and Build 🔧 17 | run: | 18 | npm install 19 | npm run build:demo:github 20 | cp dist/demo/index.html dist/demo/404.html 21 | 22 | - name: Deploy 🚀 23 | uses: JamesIves/github-pages-deploy-action@3.6.2 24 | with: 25 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 26 | BRANCH: gh-pages # The branch the action should deploy to. 27 | FOLDER: dist/demo # The folder the action should deploy. 28 | CLEAN: true # Automatically remove deleted files from the deploy branch 29 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Build and Publish to NPM 2 | on: 3 | push: 4 | tags: 5 | - 'v*.*.*' 6 | jobs: 7 | build-and-publish: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 🛎️ 11 | uses: actions/checkout@v2 12 | 13 | - name: Setup node 🔨 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: 12 17 | registry-url: https://registry.npmjs.org/ 18 | 19 | - name: Install and Build 🔧 20 | run: | 21 | npm install 22 | npm run build 23 | 24 | - name: Publish to NPM 🚀 25 | run: cd dist/fire-admin && npm publish 26 | env: 27 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 AXeL 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fire-admin", 3 | "version": "0.0.3", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build && npm run copy:readme", 8 | "copy:readme": "cp README.md dist/fire-admin/", 9 | "build:demo": "ng build demo", 10 | "build:demo:github": "ng build demo --prod --base-href \"/FireAdmin/\"", 11 | "deploy:demo:github": "ngh --dir=dist/demo", 12 | "test": "ng test", 13 | "lint": "ng lint", 14 | "e2e": "ng e2e" 15 | }, 16 | "private": true, 17 | "dependencies": { 18 | "@angular/animations": "~8.2.14", 19 | "@angular/common": "~8.2.14", 20 | "@angular/compiler": "~8.2.14", 21 | "@angular/core": "~8.2.14", 22 | "@angular/fire": "^5.4.2", 23 | "@angular/forms": "~8.2.14", 24 | "@angular/platform-browser": "~8.2.14", 25 | "@angular/platform-browser-dynamic": "~8.2.14", 26 | "@angular/router": "~8.2.14", 27 | "@fortawesome/fontawesome-free": "^5.12.1", 28 | "angular-datatables": "^8.1.0", 29 | "bootstrap": "^4.4.1", 30 | "chart.js": "^2.9.4", 31 | "datatables.net-responsive-dt": "^2.2.3", 32 | "firebase": "^7.12.0", 33 | "jquery": "^3.5.0", 34 | "material-icons-font": "^2.0.0", 35 | "popper.js": "^1.16.1", 36 | "quill": "^1.3.7", 37 | "rxjs": "~6.4.0", 38 | "shards-ui": "^3.0.0", 39 | "tslib": "^1.11.1", 40 | "zone.js": "~0.9.1" 41 | }, 42 | "devDependencies": { 43 | "@angular-devkit/build-angular": "~0.803.25", 44 | "@angular-devkit/build-ng-packagr": "~0.803.25", 45 | "@angular/cli": "~8.3.24", 46 | "@angular/compiler-cli": "~8.2.14", 47 | "@angular/language-service": "~8.2.14", 48 | "@types/datatables.net": "^1.10.18", 49 | "@types/jasmine": "~3.3.8", 50 | "@types/jasminewd2": "~2.0.3", 51 | "@types/jquery": "^3.3.33", 52 | "@types/node": "~8.9.4", 53 | "codelyzer": "^5.0.0", 54 | "jasmine-core": "~3.4.0", 55 | "jasmine-spec-reporter": "~4.2.1", 56 | "karma": "~4.1.0", 57 | "karma-chrome-launcher": "~2.2.0", 58 | "karma-coverage-istanbul-reporter": "~2.0.1", 59 | "karma-jasmine": "~2.0.1", 60 | "karma-jasmine-html-reporter": "^1.4.0", 61 | "ng-packagr": "^5.4.0", 62 | "protractor": "~5.4.0", 63 | "ts-node": "~7.0.0", 64 | "tsickle": "^0.37.0", 65 | "tslint": "~5.15.0", 66 | "typescript": "~3.5.3" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /projects/demo/browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /projects/demo/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /projects/demo/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('demo app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /projects/demo/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /projects/demo/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /projects/demo/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/demo'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/demo/src/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/demo/src/.nojekyll -------------------------------------------------------------------------------- /projects/demo/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | 5 | const routes: Routes = [ 6 | { 7 | path: 'demo', 8 | //loadChildren: () => import('fire-admin').then(m => m.FireAdminModule) 9 | loadChildren: () => import('projects/fire-admin/src/public-api').then(m => m.FireAdminModule) 10 | }, 11 | { 12 | path: '**', 13 | redirectTo: 'demo' 14 | } 15 | ]; 16 | 17 | @NgModule({ 18 | imports: [RouterModule.forRoot(routes)], 19 | exports: [RouterModule] 20 | }) 21 | export class AppRoutingModule { } 22 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/demo/src/app/app.component.css -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'demo'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('demo'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('demo app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'demo'; 10 | } 11 | -------------------------------------------------------------------------------- /projects/demo/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | //import { FireAdminModule } from 'fire-admin'; 7 | import { FireAdminModule } from 'projects/fire-admin/src/public-api'; 8 | import { environment } from '../environments/environment'; 9 | 10 | @NgModule({ 11 | declarations: [ 12 | AppComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | AppRoutingModule, 17 | FireAdminModule.initialize(environment.firebase) 18 | ], 19 | providers: [], 20 | bootstrap: [AppComponent] 21 | }) 22 | export class AppModule { } 23 | -------------------------------------------------------------------------------- /projects/demo/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/demo/src/assets/.gitkeep -------------------------------------------------------------------------------- /projects/demo/src/assets/images/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /projects/demo/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | firebase: { 4 | apiKey: "AIzaSyDM1ybQFpUe3fJ046KAfJeoiBHl5M51Rt0", 5 | authDomain: "fireadmin-74e50.firebaseapp.com", 6 | databaseURL: "https://fireadmin-74e50.firebaseio.com", 7 | projectId: "fireadmin-74e50", 8 | storageBucket: "fireadmin-74e50.appspot.com", 9 | messagingSenderId: "1081829121945", 10 | appId: "1:1081829121945:web:349839b2c6846c71143d08" 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /projects/demo/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false, 7 | firebase: { 8 | apiKey: "AIzaSyDM1ybQFpUe3fJ046KAfJeoiBHl5M51Rt0", 9 | authDomain: "fireadmin-74e50.firebaseapp.com", 10 | databaseURL: "https://fireadmin-74e50.firebaseio.com", 11 | projectId: "fireadmin-74e50", 12 | storageBucket: "fireadmin-74e50.appspot.com", 13 | messagingSenderId: "1081829121945", 14 | appId: "1:1081829121945:web:349839b2c6846c71143d08" 15 | } 16 | }; 17 | 18 | /* 19 | * For easier debugging in development mode, you can import the following file 20 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 21 | * 22 | * This import should be commented out in production mode because it will have a negative impact 23 | * on performance if an error is thrown. 24 | */ 25 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 26 | -------------------------------------------------------------------------------- /projects/demo/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/demo/src/favicon.ico -------------------------------------------------------------------------------- /projects/demo/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Demo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /projects/demo/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /projects/demo/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | 65 | (window as any).global = window; 66 | -------------------------------------------------------------------------------- /projects/demo/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /projects/demo/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /projects/demo/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.ts" 13 | ], 14 | "exclude": [ 15 | "src/test.ts", 16 | "src/**/*.spec.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /projects/demo/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /projects/demo/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /projects/fire-admin/README.md: -------------------------------------------------------------------------------- 1 | # FireAdmin 2 | 3 | This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.14. 4 | 5 | ## Code scaffolding 6 | 7 | Run `ng generate component component-name --project FireAdmin` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project FireAdmin`. 8 | > Note: Don't forget to add `--project FireAdmin` or else it will be added to the default project in your `angular.json` file. 9 | 10 | ## Build 11 | 12 | Run `ng build FireAdmin` to build the project. The build artifacts will be stored in the `dist/` directory. 13 | 14 | ## Publishing 15 | 16 | After building your library with `ng build FireAdmin`, go to the dist folder `cd dist/fire-admin` and run `npm publish`. 17 | 18 | ## Running unit tests 19 | 20 | Run `ng test FireAdmin` to execute the unit tests via [Karma](https://karma-runner.github.io). 21 | 22 | ## Further help 23 | 24 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 25 | -------------------------------------------------------------------------------- /projects/fire-admin/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../../coverage/fire-admin'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /projects/fire-admin/ng-package.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", 3 | "dest": "../../dist/fire-admin", 4 | "lib": { 5 | "entryFile": "src/public-api.ts", 6 | "umdModuleIds": { 7 | "@angular/fire": "@angular/fire", 8 | "@fortawesome/fontawesome-free": "@fortawesome/fontawesome-free", 9 | "angular-datatables": "angular-datatables", 10 | "bootstrap": "bootstrap", 11 | "chart.js": "chart.js", 12 | "datatables.net-responsive-dt": "datatables.net-responsive-dt", 13 | "firebase": "firebase", 14 | "jquery": "jquery", 15 | "material-icons-font": "material-icons-font", 16 | "popper.js": "popper.js", 17 | "quill": "quill", 18 | "shards-ui": "shards-ui" 19 | } 20 | }, 21 | "whitelistedNonPeerDependencies": [ 22 | "@angular/fire", 23 | "@fortawesome/fontawesome-free", 24 | "angular-datatables", 25 | "bootstrap", 26 | "chart.js", 27 | "datatables.net-responsive-dt", 28 | "@types/datatables.net", 29 | "firebase", 30 | "jquery", 31 | "material-icons-font", 32 | "popper.js", 33 | "quill", 34 | "shards-ui" 35 | ] 36 | } -------------------------------------------------------------------------------- /projects/fire-admin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-fire-admin", 3 | "version": "0.0.3", 4 | "description": "A mini headless CMS around Angular & Firebase.", 5 | "keywords": [ 6 | "Angular", 7 | "Firebase", 8 | "Firestore", 9 | "CMS", 10 | "Headless" 11 | ], 12 | "license": "MIT", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/FirebaseGoodies/FireAdmin" 16 | }, 17 | "homepage": "https://firebasegoodies.github.io/FireAdmin/demo/login?email=guest@fireadmin.com&password=fireadmin", 18 | "dependencies": { 19 | "@angular/fire": "^5.4.2", 20 | "@fortawesome/fontawesome-free": "^5.12.1", 21 | "angular-datatables": "^8.1.0", 22 | "bootstrap": "^4.4.1", 23 | "chart.js": "^2.9.3", 24 | "datatables.net-responsive-dt": "^2.2.3", 25 | "@types/datatables.net": "^1.10.18", 26 | "firebase": "^7.12.0", 27 | "jquery": "^3.4.1", 28 | "material-icons-font": "^2.0.0", 29 | "popper.js": "^1.16.1", 30 | "quill": "^1.3.7", 31 | "shards-ui": "^3.0.0" 32 | }, 33 | "devDependencies": { 34 | }, 35 | "peerDependencies": { 36 | "@angular/common": "^8.2.14", 37 | "@angular/core": "^8.2.14" 38 | } 39 | } -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/dashboard/dashboard.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/dashboard/dashboard.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/dashboard/dashboard.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DashboardComponent } from './dashboard.component'; 4 | 5 | describe('DashboardComponent', () => { 6 | let component: DashboardComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DashboardComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DashboardComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/login/login.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/login/login.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/login/login.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 |
7 |
8 | 15 |
16 |
17 | 18 |
{{ 'SignInToYourAccount' | translate }}
19 |
20 |
21 | 22 | 23 |
24 |
25 | 26 | 27 |
28 |
29 |
30 | 31 | 32 |
33 |
34 | 35 |
36 |
37 | 45 |
46 | 50 |
51 |
52 |
53 |
54 |
55 |
56 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { Subscription } from 'rxjs'; 3 | import { AuthService } from '../../services/auth.service'; 4 | import { NavigationService } from '../../services/navigation.service'; 5 | import { ActivatedRoute } from '@angular/router'; 6 | import { getLogo } from '../../helpers/assets.helper'; 7 | 8 | @Component({ 9 | selector: 'fa-login', 10 | templateUrl: './login.component.html', 11 | styleUrls: ['./login.component.css'] 12 | }) 13 | export class LoginComponent implements OnInit, OnDestroy { 14 | 15 | logo: string = getLogo(); 16 | email: string = ''; 17 | password: string = ''; 18 | rememberMe: boolean = false; 19 | error: string = null; 20 | private routeSubscription: Subscription = null; 21 | 22 | constructor(private auth: AuthService, private route: ActivatedRoute, private navigation: NavigationService) { } 23 | 24 | ngOnInit() { 25 | this.routeSubscription = this.route.queryParams.subscribe((params: any) => { 26 | //console.log(params); 27 | if (params.email) { 28 | this.email = params.email; 29 | } 30 | if (params.password) { 31 | this.password = params.password; 32 | } 33 | }); 34 | } 35 | 36 | ngOnDestroy() { 37 | if (this.routeSubscription) { 38 | this.routeSubscription.unsubscribe(); 39 | } 40 | } 41 | 42 | onSubmit() { 43 | this.auth.signIn(this.email, this.password, this.rememberMe).then(() => { 44 | this.navigation.redirectTo('dashboard'); 45 | }).catch((error: Error) => { 46 | this.error = error.message; 47 | }); 48 | } 49 | 50 | dismissError(event: Event) { 51 | event.preventDefault(); 52 | event.stopPropagation(); 53 | this.error = null; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/logout/logout.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/logout/logout.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/logout/logout.component.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/logout/logout.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LogoutComponent } from './logout.component'; 4 | 5 | describe('LogoutComponent', () => { 6 | let component: LogoutComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LogoutComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LogoutComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/logout/logout.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AuthService } from '../../services/auth.service'; 3 | import { AlertService } from '../../services/alert.service'; 4 | import { NavigationService } from '../../services/navigation.service'; 5 | 6 | @Component({ 7 | selector: 'fa-logout', 8 | templateUrl: './logout.component.html', 9 | styleUrls: ['./logout.component.css'] 10 | }) 11 | export class LogoutComponent implements OnInit { 12 | 13 | constructor(private auth: AuthService, private alert: AlertService, private navigation: NavigationService) { } 14 | 15 | ngOnInit() { 16 | this.auth.signOut().then(() => { 17 | this.navigation.redirectTo('login'); 18 | }).catch((error: Error) => { 19 | this.alert.error(error.message); 20 | }); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/add/pages-add.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/pages/add/pages-add.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/add/pages-add.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 | 26 |
27 | 28 |
29 |
30 | {{ 'PageBlocks' | translate }} 31 |
32 |
33 |
34 |
35 |
36 |
37 |
{{ block.key?.length ? block.key : ('PageBlock' | translate) }}
38 | 39 | delete_outline 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |
{{ 'Actions' | translate }}
62 |
63 |
64 |
    65 |
  • 66 | 67 | translate{{ 'PageLanguage' | translate }}: 68 | 71 | 72 | 73 | link{{ 'PageSlug' | translate }}: 74 | 75 | 76 |
  • 77 |
  • 78 | 81 |
  • 82 |
83 |
84 |
85 | 86 |
87 |
88 |
89 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/add/pages-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PagesAddComponent } from './pages-add.component'; 4 | 5 | describe('PagesAddComponent', () => { 6 | let component: PagesAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PagesAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PagesAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/add/pages-add.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { slugify } from '../../../helpers/functions.helper'; 3 | import { Language } from '../../../models/language.model'; 4 | import { SettingsService } from '../../../services/settings.service'; 5 | import { PageBlock, PageBlockType } from '../../../models/collections/page.model'; 6 | import { I18nService } from '../../../services/i18n.service'; 7 | import { PagesService } from '../../../services/collections/pages.service'; 8 | import { AlertService } from '../../../services/alert.service'; 9 | import { NavigationService } from '../../../services/navigation.service'; 10 | 11 | @Component({ 12 | selector: 'fa-pages-add', 13 | templateUrl: './pages-add.component.html', 14 | styleUrls: ['./pages-add.component.css'] 15 | }) 16 | export class PagesAddComponent implements OnInit { 17 | 18 | title: string; 19 | slug: string; 20 | language: string; 21 | languages: Language[]; 22 | blocks: PageBlock[] = []; 23 | blockTypes: { label: string, value: PageBlockType }[] = []; 24 | 25 | constructor( 26 | private settings: SettingsService, 27 | private i18n: I18nService, 28 | private pages: PagesService, 29 | private alert: AlertService, 30 | private navigation: NavigationService 31 | ) { } 32 | 33 | ngOnInit() { 34 | this.languages = this.settings.getActiveSupportedLanguages(); 35 | this.language = this.languages[0].key; 36 | this.blockTypes = Object.keys(PageBlockType).map((key: string) => { 37 | return { label: key, value: PageBlockType[key] }; 38 | }); 39 | //this.addBlock(); 40 | } 41 | 42 | onTitleInput() { 43 | this.slug = slugify(this.title).substr(0, 50); 44 | } 45 | 46 | addBlock(event?: Event) { 47 | this.blocks.push({ 48 | name: '', 49 | type: PageBlockType.Text, 50 | content: '' 51 | }); 52 | } 53 | 54 | removeBlock(index: number) { 55 | this.blocks.splice(index, 1); 56 | } 57 | 58 | onBlockNameInput(block: PageBlock) { 59 | block.key = slugify(block.name); 60 | } 61 | 62 | addPage(event: Event) { 63 | const addButon = event.target as any; 64 | const startLoading = () => { 65 | addButon.isLoading = true; 66 | }; 67 | const stopLoading = () => { 68 | addButon.isLoading = false; 69 | }; 70 | startLoading(); 71 | // Check if page slug is duplicated 72 | this.pages.isSlugDuplicated(this.slug, this.language).then((duplicated: boolean) => { 73 | if (duplicated) { 74 | // Warn user about page slug 75 | this.alert.warning(this.i18n.get('PageSlugAlreadyExists'), false, 5000); 76 | stopLoading(); 77 | } else { 78 | // Add page 79 | this.pages.add({ 80 | lang: this.language, 81 | title: this.title, 82 | slug: this.slug, 83 | blocks: this.pages.formatBlocks(this.blocks) 84 | }).then(() => { 85 | this.alert.success(this.i18n.get('PageAdded'), false, 5000, true); 86 | this.navigation.redirectTo('pages', 'list'); 87 | }).catch((error: Error) => { 88 | this.alert.error(error.message); 89 | }).finally(() => { 90 | stopLoading(); 91 | }); 92 | } 93 | }).catch((error: Error) => { 94 | this.alert.error(error.message); 95 | stopLoading(); 96 | }); 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/edit/pages-edit.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/pages/edit/pages-edit.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/edit/pages-edit.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 | 26 |
27 | 28 |
29 |
30 | {{ 'PageBlocks' | translate }} 31 |
32 |
33 |
34 |
35 |
36 |
37 |
{{ block.key?.length ? block.key : ('PageBlock' | translate) }}
38 | 39 | delete_outline 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |
{{ 'Actions' | translate }}
62 |
63 |
64 |
    65 |
  • 66 | 67 | link{{ 'PageSlug' | translate }}: 68 | 69 | 70 |
  • 71 |
  • 72 | 75 | 78 |
  • 79 |
80 |
81 |
82 | 83 |
84 |
85 |
86 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/edit/pages-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PagesEditComponent } from './pages-edit.component'; 4 | 5 | describe('PagesEditComponent', () => { 6 | let component: PagesEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PagesEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PagesEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/edit/pages-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { slugify } from '../../../helpers/functions.helper'; 3 | import { PageBlock, PageBlockType, Page } from '../../../models/collections/page.model'; 4 | import { I18nService } from '../../../services/i18n.service'; 5 | import { PagesService } from '../../../services/collections/pages.service'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { NavigationService } from '../../../services/navigation.service'; 8 | import { Subscription, Subject } from 'rxjs'; 9 | import { ActivatedRoute } from '@angular/router'; 10 | import { take } from 'rxjs/operators'; 11 | 12 | @Component({ 13 | selector: 'fa-pages-edit', 14 | templateUrl: './pages-edit.component.html', 15 | styleUrls: ['./pages-edit.component.css'] 16 | }) 17 | export class PagesEditComponent implements OnInit, OnDestroy { 18 | 19 | private id: string; 20 | title: string; 21 | slug: string; 22 | language: string; 23 | blocks: PageBlock[] = []; 24 | blockTypes: { label: string, value: PageBlockType }[] = []; 25 | isSubmitButtonsDisabled: boolean = false; 26 | private subscription: Subscription = new Subscription(); 27 | private routeParamsChange: Subject = new Subject(); 28 | 29 | constructor( 30 | private i18n: I18nService, 31 | private pages: PagesService, 32 | private alert: AlertService, 33 | public navigation: NavigationService, 34 | private route: ActivatedRoute 35 | ) { } 36 | 37 | ngOnInit() { 38 | this.blockTypes = Object.keys(PageBlockType).map((key: string) => { 39 | return { label: key, value: PageBlockType[key] }; 40 | }); 41 | this.isSubmitButtonsDisabled = true; 42 | this.subscription.add( 43 | this.route.params.subscribe((params: { id: string }) => { 44 | // console.log(params); 45 | this.pages.get(params.id).pipe(take(1)).toPromise().then((page: Page) => { 46 | // console.log(page); 47 | if (page) { 48 | this.id = page.id; 49 | this.title = page.title; 50 | this.slug = page.slug; 51 | this.language = page.lang; 52 | this.blocks = Object.keys(page.blocks).map((key: string) => { 53 | const block: PageBlock = page.blocks[key]; 54 | return { 55 | key: key, 56 | name: block.name, 57 | type: block.type, 58 | content: block.content 59 | }; 60 | }); 61 | this.routeParamsChange.next(); 62 | this.isSubmitButtonsDisabled = false; 63 | } else { 64 | this.navigation.redirectTo('pages', 'list'); 65 | } 66 | }); 67 | }) 68 | ); 69 | } 70 | 71 | ngOnDestroy() { 72 | this.subscription.unsubscribe(); 73 | this.routeParamsChange.next(); 74 | } 75 | 76 | onTitleInput() { 77 | this.slug = slugify(this.title).substr(0, 50); 78 | } 79 | 80 | addBlock(event?: Event) { 81 | this.blocks.push({ 82 | name: '', 83 | type: PageBlockType.Text, 84 | content: '' 85 | }); 86 | } 87 | 88 | removeBlock(index: number) { 89 | this.blocks.splice(index, 1); 90 | } 91 | 92 | onBlockNameInput(block: PageBlock) { 93 | block.key = slugify(block.name); 94 | } 95 | 96 | savePage(event: Event) { 97 | const target = event.target as any; 98 | const startLoading = () => { 99 | target.isLoading = true; 100 | this.isSubmitButtonsDisabled = true; 101 | }; 102 | const stopLoading = () => { 103 | target.isLoading = false; 104 | this.isSubmitButtonsDisabled = false; 105 | }; 106 | startLoading(); 107 | // Check if page slug is duplicated 108 | this.pages.isSlugDuplicated(this.slug, this.language, this.id).then((duplicated: boolean) => { 109 | if (duplicated) { 110 | // Warn user about page slug 111 | this.alert.warning(this.i18n.get('PageSlugAlreadyExists'), false, 5000); 112 | stopLoading(); 113 | } else { 114 | // Edit page 115 | const data: Page = { 116 | lang: this.language, 117 | title: this.title, 118 | slug: this.slug, 119 | blocks: this.pages.formatBlocks(this.blocks) 120 | }; 121 | this.pages.edit(this.id, data).then(() => { 122 | this.alert.success(this.i18n.get('PageSaved'), false, 5000, true); 123 | this.navigation.redirectTo('pages', 'list'); 124 | }).catch((error: Error) => { 125 | this.alert.error(error.message); 126 | }).finally(() => { 127 | stopLoading(); 128 | }); 129 | } 130 | }).catch((error: Error) => { 131 | this.alert.error(error.message); 132 | stopLoading(); 133 | }); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/list/pages-list.component.css: -------------------------------------------------------------------------------- 1 | .lo-stats__order-details { 2 | min-width: 200px; 3 | } 4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/list/pages-list.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 |
12 |
13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 34 | 38 | 39 | 40 | 41 | 46 | 59 | 60 | 61 |
{{ 'PageTitle' | translate }}{{ 'PageLanguage' | translate }}{{ 'PageCreatedAt' | translate }}{{ 'PageUpdatedAt' | translate }}{{ 'PageAuthor' | translate }}{{ 'Actions' | translate }}
30 |
31 | insert_drive_file 32 |
33 |
35 | {{ page.title }} 36 | {{ '/' + page.slug }} 37 | {{ allLanguages[page.lang].label | translate }}{{ page.createdAt | datetime }}{{ page.updatedAt | datetime }} 42 | 43 | {{ page.author | async }} 44 | 45 | 47 |
48 | 51 | 54 | 57 |
58 |
62 |
63 |
64 |
65 |
66 |
67 | 68 | 69 | 86 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/list/pages-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PagesListComponent } from './pages-list.component'; 4 | 5 | describe('PagesListComponent', () => { 6 | let component: PagesListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PagesListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PagesListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/list/pages-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; 2 | import { DataTableDirective } from 'angular-datatables'; 3 | import { Subject, Subscription, Observable } from 'rxjs'; 4 | import { map, takeUntil } from 'rxjs/operators'; 5 | import { refreshDataTable } from '../../../helpers/datatables.helper'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { NavigationService } from '../../../services/navigation.service'; 8 | import { I18nService } from '../../../services/i18n.service'; 9 | import { ActivatedRoute } from '@angular/router'; 10 | import { SettingsService } from '../../../services/settings.service'; 11 | import { Language } from '../../../models/language.model'; 12 | import { PagesService } from '../../../services/collections/pages.service'; 13 | import { Page } from '../../../models/collections/page.model'; 14 | import { CurrentUserService } from '../../../services/current-user.service'; 15 | 16 | @Component({ 17 | selector: 'fa-pages-list', 18 | templateUrl: './pages-list.component.html', 19 | styleUrls: ['./pages-list.component.css'] 20 | }) 21 | export class PagesListComponent implements OnInit, OnDestroy { 22 | 23 | allPages: Observable; 24 | selectedPage: Page = null; 25 | @ViewChild(DataTableDirective, {static : false}) private dataTableElement: DataTableDirective; 26 | dataTableOptions: DataTables.Settings|any = { 27 | responsive: true, 28 | aaSorting: [] 29 | }; 30 | dataTableTrigger: Subject = new Subject(); 31 | private subscription: Subscription = new Subscription(); 32 | private routeParamsChange: Subject = new Subject(); 33 | allLanguages: Language[] = []; 34 | isLoading: boolean = true; 35 | 36 | constructor( 37 | private pages: PagesService, 38 | private alert: AlertService, 39 | private i18n: I18nService, 40 | private route: ActivatedRoute, 41 | public navigation: NavigationService, 42 | public currentUser: CurrentUserService, 43 | private settings: SettingsService 44 | ) { } 45 | 46 | ngOnInit() { 47 | // Get all languages 48 | this.settings.supportedLanguages.forEach((language: Language) => { 49 | this.allLanguages[language.key] = language; 50 | }); 51 | // Get route params 52 | this.subscription.add( 53 | this.route.params.subscribe((params: { authorId: string }) => { 54 | this.routeParamsChange.next(); 55 | this.isLoading = true; 56 | // Get all pages 57 | this.allPages = this.pages.getWhereFn(ref => { 58 | let query: any = ref; 59 | // Filter by author 60 | if (params.authorId) { 61 | query = query.where('createdBy', '==', params.authorId); 62 | } 63 | //query = query.orderBy('createdAt', 'desc'); // requires an index to work 64 | return query; 65 | }, true).pipe( 66 | map((pages: Page[]) => { 67 | return pages.sort((a: Page, b: Page) => b.createdAt - a.createdAt); 68 | }), 69 | takeUntil(this.routeParamsChange) 70 | ); 71 | this.subscription.add( 72 | this.allPages.subscribe((pages: Page[]) => { 73 | // console.log(pages); 74 | // Refresh datatable on data change 75 | refreshDataTable(this.dataTableElement, this.dataTableTrigger); 76 | this.isLoading = false; 77 | }) 78 | ); 79 | }) 80 | ); 81 | } 82 | 83 | ngOnDestroy() { 84 | this.dataTableTrigger.unsubscribe(); 85 | this.subscription.unsubscribe(); 86 | this.routeParamsChange.next(); 87 | } 88 | 89 | deletePage(page: Page) { 90 | this.pages.delete(page.id, { 91 | lang: page.lang, 92 | translationId: page.translationId, 93 | translations: page.translations 94 | }).then(() => { 95 | this.alert.success(this.i18n.get('PageDeleted', { title: page.title }), false, 5000); 96 | }).catch((error: Error) => { 97 | this.alert.error(error.message); 98 | }); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/translate/pages-translate.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/pages/translate/pages-translate.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/translate/pages-translate.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 |
11 |
12 | 13 |
14 |
15 |
16 | 17 |
18 |
19 | 26 |
27 | 28 |
29 |
30 | {{ 'PageBlocks' | translate }} 31 |
32 |
33 |
34 |
35 |
36 |
37 |
{{ block.key?.length ? block.key : ('PageBlock' | translate) }}
38 | 39 | delete_outline 40 | 41 | 42 |
43 |
44 |
45 |
46 | 47 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 | 59 |
60 |
61 |
{{ 'Actions' | translate }}
62 |
63 |
64 |
    65 |
  • 66 | 67 | translate{{ 'PageLanguage' | translate }}: 68 | 71 | 72 | 73 | link{{ 'PageSlug' | translate }}: 74 | 75 | 76 |
  • 77 |
  • 78 | 81 |
  • 82 |
83 |
84 |
85 | 86 |
87 |
88 |
89 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/translate/pages-translate.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PagesTranslateComponent } from './pages-translate.component'; 4 | 5 | describe('PagesTranslateComponent', () => { 6 | let component: PagesTranslateComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PagesTranslateComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PagesTranslateComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/pages/translate/pages-translate.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { slugify } from '../../../helpers/functions.helper'; 3 | import { PageBlock, PageBlockType, Page } from '../../../models/collections/page.model'; 4 | import { I18nService } from '../../../services/i18n.service'; 5 | import { PagesService } from '../../../services/collections/pages.service'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { NavigationService } from '../../../services/navigation.service'; 8 | import { Subscription, Subject } from 'rxjs'; 9 | import { ActivatedRoute } from '@angular/router'; 10 | import { take } from 'rxjs/operators'; 11 | import { Language } from '../../../models/language.model'; 12 | 13 | @Component({ 14 | selector: 'fa-pages-translate', 15 | templateUrl: './pages-translate.component.html', 16 | styleUrls: ['./pages-translate.component.css'] 17 | }) 18 | export class PagesTranslateComponent implements OnInit, OnDestroy { 19 | 20 | private origin: Page; 21 | title: string; 22 | slug: string; 23 | language: string; 24 | languages: Language[]; 25 | blocks: PageBlock[] = []; 26 | blockTypes: { label: string, value: PageBlockType }[] = []; 27 | isSubmitButtonsDisabled: boolean = false; 28 | private subscription: Subscription = new Subscription(); 29 | private routeParamsChange: Subject = new Subject(); 30 | 31 | constructor( 32 | private i18n: I18nService, 33 | private pages: PagesService, 34 | private alert: AlertService, 35 | private navigation: NavigationService, 36 | private route: ActivatedRoute 37 | ) { } 38 | 39 | ngOnInit() { 40 | this.blockTypes = Object.keys(PageBlockType).map((key: string) => { 41 | return { label: key, value: PageBlockType[key] }; 42 | }); 43 | this.isSubmitButtonsDisabled = true; 44 | this.subscription.add( 45 | this.route.params.subscribe((params: { id: string }) => { 46 | // console.log(params); 47 | this.pages.get(params.id).pipe(take(1)).toPromise().then((page: Page) => { 48 | // console.log(page); 49 | if (page) { 50 | this.languages = this.pages.getTranslationLanguages(page); 51 | if (this.languages.length) { 52 | this.origin = page; 53 | this.language = this.languages[0].key; 54 | this.title = page.title; 55 | this.slug = page.slug; 56 | this.blocks = Object.keys(page.blocks).map((key: string) => { 57 | const block: PageBlock = page.blocks[key]; 58 | return { 59 | key: key, 60 | name: block.name, 61 | type: block.type, 62 | content: block.content 63 | }; 64 | }); 65 | this.routeParamsChange.next(); 66 | this.isSubmitButtonsDisabled = false; 67 | } else { 68 | this.navigation.redirectTo('pages', 'list'); 69 | } 70 | } else { 71 | this.navigation.redirectTo('pages', 'list'); 72 | } 73 | }); 74 | }) 75 | ); 76 | } 77 | 78 | ngOnDestroy() { 79 | this.subscription.unsubscribe(); 80 | this.routeParamsChange.next(); 81 | } 82 | 83 | onTitleInput() { 84 | this.slug = slugify(this.title).substr(0, 50); 85 | } 86 | 87 | addBlock(event?: Event) { 88 | this.blocks.push({ 89 | name: '', 90 | type: PageBlockType.Text, 91 | content: '' 92 | }); 93 | } 94 | 95 | removeBlock(index: number) { 96 | this.blocks.splice(index, 1); 97 | } 98 | 99 | onBlockNameInput(block: PageBlock) { 100 | block.key = slugify(block.name); 101 | } 102 | 103 | addPage(event: Event) { 104 | const addButon = event.target as any; 105 | const startLoading = () => { 106 | addButon.isLoading = true; 107 | }; 108 | const stopLoading = () => { 109 | addButon.isLoading = false; 110 | }; 111 | startLoading(); 112 | // Check if page slug is duplicated 113 | this.pages.isSlugDuplicated(this.slug, this.language).then((duplicated: boolean) => { 114 | if (duplicated) { 115 | // Warn user about page slug 116 | this.alert.warning(this.i18n.get('PageSlugAlreadyExists'), false, 5000); 117 | stopLoading(); 118 | } else { 119 | // Add page 120 | this.pages.translate({ 121 | lang: this.language, 122 | title: this.title, 123 | slug: this.slug, 124 | blocks: this.pages.formatBlocks(this.blocks), 125 | translationId: this.origin.translationId 126 | }).then(() => { 127 | this.alert.success(this.i18n.get('PageAdded'), false, 5000, true); 128 | this.navigation.redirectTo('pages', 'list'); 129 | }).catch((error: Error) => { 130 | this.alert.error(error.message); 131 | }).finally(() => { 132 | stopLoading(); 133 | }); 134 | } 135 | }).catch((error: Error) => { 136 | this.alert.error(error.message); 137 | stopLoading(); 138 | }); 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/add/posts-add.component.css: -------------------------------------------------------------------------------- 1 | .ql-container { 2 | min-height: 480px; 3 | } 4 | 5 | ::ng-deep .ql-html:after { 6 | content: "#"; 7 | } 8 | 9 | ::ng-deep #editor-container .ql-html-editor { 10 | position: absolute; 11 | background: #fffff0; 12 | top: 0; 13 | left: 0; 14 | bottom: 0; 15 | width: 100%; 16 | border: 0; 17 | padding: 12px; 18 | box-sizing: border-box; 19 | } 20 | 21 | .categories-list .list-group-item { 22 | max-height: 150px; 23 | overflow-y: auto; 24 | } 25 | 26 | .edit-user-details__avatar { 27 | width: 100%; 28 | text-align: center; 29 | max-width: 100%; 30 | box-shadow: none; 31 | } 32 | 33 | .edit-user-details__avatar img { 34 | width: auto; 35 | /*max-width: 7.5rem;*/ 36 | max-height: 9.5rem; 37 | } 38 | 39 | .edit-user-details__avatar__change i { 40 | line-height: 8.5rem; 41 | } 42 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/add/posts-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostsAddComponent } from './posts-add.component'; 4 | 5 | describe('PostsAddComponent', () => { 6 | let component: PostsAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostsAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostsAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/categories/posts-categories.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/posts/categories/posts-categories.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/categories/posts-categories.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostsCategoriesComponent } from './posts-categories.component'; 4 | 5 | describe('PostsCategoriesComponent', () => { 6 | let component: PostsCategoriesComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostsCategoriesComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostsCategoriesComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/categories/posts-categories.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; 2 | import { SettingsService } from '../../../services/settings.service'; 3 | import { Language } from '../../../models/language.model'; 4 | import { slugify } from '../../../helpers/functions.helper'; 5 | import { CategoriesService } from '../../../services/collections/categories.service'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { I18nService } from '../../../services/i18n.service'; 8 | import { Category } from '../../../models/collections/category.model'; 9 | import { Observable, Subject, Subscription } from 'rxjs'; 10 | import { DataTableDirective } from 'angular-datatables'; 11 | import { map } from 'rxjs/operators'; 12 | import { refreshDataTable } from '../../../helpers/datatables.helper'; 13 | 14 | @Component({ 15 | selector: 'fa-posts-categories', 16 | templateUrl: './posts-categories.component.html', 17 | styleUrls: ['./posts-categories.component.css'] 18 | }) 19 | export class PostsCategoriesComponent implements OnInit, OnDestroy { 20 | 21 | label: string; 22 | slug: string; 23 | language: string; 24 | languages: Language[]; 25 | allLanguages: Language[] = []; 26 | allCategories: Observable; 27 | selectedCategory: Category = null; 28 | @ViewChild(DataTableDirective, {static : false}) private dataTableElement: DataTableDirective; 29 | dataTableOptions: DataTables.Settings|any = { 30 | responsive: true, 31 | aaSorting: [] 32 | }; 33 | dataTableTrigger: Subject = new Subject(); 34 | private subscription: Subscription = new Subscription(); 35 | 36 | constructor( 37 | private settings: SettingsService, 38 | private categories: CategoriesService, 39 | private alert: AlertService, 40 | private i18n: I18nService 41 | ) { } 42 | 43 | ngOnInit() { 44 | // Get active languages 45 | this.languages = this.settings.getActiveSupportedLanguages(); 46 | this.language = this.languages[0].key; 47 | // Get all languages 48 | this.settings.supportedLanguages.forEach((language: Language) => { 49 | this.allLanguages[language.key] = language; 50 | }); 51 | // Get all categories 52 | this.allCategories = this.categories.getAll().pipe(map((categories: Category[]) => { 53 | return categories.sort((a: Category, b: Category) => b.createdAt - a.createdAt); 54 | })); 55 | this.subscription.add( 56 | this.allCategories.subscribe((categories: Category[]) => { 57 | // console.log(categories); 58 | // Refresh datatable on data change 59 | refreshDataTable(this.dataTableElement, this.dataTableTrigger, true); 60 | }) 61 | ); 62 | } 63 | 64 | ngOnDestroy() { 65 | this.dataTableTrigger.unsubscribe(); 66 | this.subscription.unsubscribe(); 67 | } 68 | 69 | onAddCategoryLabelInput() { 70 | this.slug = slugify(this.label); 71 | } 72 | 73 | addCategory(event: Event) { 74 | (event.target as any).disabled = true; 75 | this.categories.add({ 76 | label: this.label, 77 | slug: this.slug, 78 | lang: this.language 79 | }).then(() => { 80 | this.alert.success(this.i18n.get('CategoryAdded'), false, 5000); 81 | }).catch((error: Error) => { 82 | this.alert.error(error.message); 83 | }).finally(() => { 84 | this.label = this.slug = ''; 85 | }); 86 | } 87 | 88 | deleteCategory(category: Category) { 89 | this.categories.delete(category.id).then(() => { 90 | this.alert.success(this.i18n.get('CategoryDeleted', { label: category.label }), false, 5000); 91 | }).catch((error: Error) => { 92 | this.alert.error(error.message); 93 | }); 94 | } 95 | 96 | onEditCategoryLabelInput() { 97 | this.selectedCategory.slug = slugify(this.selectedCategory.label); 98 | } 99 | 100 | editCategory(category: Category) { 101 | this.categories.edit(category.id, category).then(() => { 102 | this.alert.success(this.i18n.get('CategorySaved', { label: category.label }), false, 5000); 103 | }).catch((error: Error) => { 104 | this.alert.error(error.message); 105 | }); 106 | } 107 | 108 | setSelectedCategory(category: Category) { 109 | this.selectedCategory = Object.assign({}, category); 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/edit/posts-edit.component.css: -------------------------------------------------------------------------------- 1 | .ql-container { 2 | min-height: 480px; 3 | } 4 | 5 | ::ng-deep .ql-html:after { 6 | content: "#"; 7 | } 8 | 9 | ::ng-deep #editor-container .ql-html-editor { 10 | position: absolute; 11 | background: #fffff0; 12 | top: 0; 13 | left: 0; 14 | bottom: 0; 15 | width: 100%; 16 | border: 0; 17 | padding: 12px; 18 | box-sizing: border-box; 19 | } 20 | 21 | .categories-list .list-group-item { 22 | max-height: 150px; 23 | overflow-y: auto; 24 | } 25 | 26 | .edit-user-details__avatar { 27 | width: 100%; 28 | text-align: center; 29 | max-width: 100%; 30 | box-shadow: none; 31 | } 32 | 33 | .edit-user-details__avatar img { 34 | width: auto; 35 | /*max-width: 7.5rem;*/ 36 | max-height: 9.5rem; 37 | } 38 | 39 | .edit-user-details__avatar__change i { 40 | line-height: 8.5rem; 41 | } 42 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/edit/posts-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostsEditComponent } from './posts-edit.component'; 4 | 5 | describe('PostsEditComponent', () => { 6 | let component: PostsEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostsEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostsEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/list/posts-list.component.css: -------------------------------------------------------------------------------- 1 | /* ::ng-deep .dataTables_wrapper { 2 | display: table; 3 | } */ 4 | 5 | .lo-stats__order-details { 6 | min-width: 200px; 7 | } 8 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/list/posts-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostsListComponent } from './posts-list.component'; 4 | 5 | describe('PostsListComponent', () => { 6 | let component: PostsListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostsListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostsListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/translate/posts-translate.component.css: -------------------------------------------------------------------------------- 1 | .ql-container { 2 | min-height: 480px; 3 | } 4 | 5 | ::ng-deep .ql-html:after { 6 | content: "#"; 7 | } 8 | 9 | ::ng-deep #editor-container .ql-html-editor { 10 | position: absolute; 11 | background: #fffff0; 12 | top: 0; 13 | left: 0; 14 | bottom: 0; 15 | width: 100%; 16 | border: 0; 17 | padding: 12px; 18 | box-sizing: border-box; 19 | } 20 | 21 | .categories-list .list-group-item { 22 | max-height: 150px; 23 | overflow-y: auto; 24 | } 25 | 26 | .edit-user-details__avatar { 27 | width: 100%; 28 | text-align: center; 29 | max-width: 100%; 30 | box-shadow: none; 31 | } 32 | 33 | .edit-user-details__avatar img { 34 | width: auto; 35 | /*max-width: 7.5rem;*/ 36 | max-height: 9.5rem; 37 | } 38 | 39 | .edit-user-details__avatar__change i { 40 | line-height: 8.5rem; 41 | } 42 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/posts/translate/posts-translate.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PostsTranslateComponent } from './posts-translate.component'; 4 | 5 | describe('PostsTranslateComponent', () => { 6 | let component: PostsTranslateComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PostsTranslateComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PostsTranslateComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/register/register.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/register/register.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/register/register.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 |
7 |
8 | 15 |
16 |
17 | 18 |
{{ 'WelcomeToFireAdmin' | translate }}
19 |
20 |
21 | 22 | 23 |
24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 |
32 | 35 |
36 |
37 |
38 | 41 |
42 |
43 |
44 |
45 |
46 |
47 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/register/register.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { RegisterComponent } from './register.component'; 4 | 5 | describe('RegisterComponent', () => { 6 | let component: RegisterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ RegisterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(RegisterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/register/register.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { getLogo } from '../../helpers/assets.helper'; 3 | import { NavigationService } from '../../services/navigation.service'; 4 | import { UsersService } from '../../services/collections/users.service'; 5 | import { UserRole } from '../../models/collections/user.model'; 6 | 7 | @Component({ 8 | selector: 'fa-register', 9 | templateUrl: './register.component.html', 10 | styleUrls: ['./register.component.css'] 11 | }) 12 | export class RegisterComponent implements OnInit { 13 | 14 | logo: string = getLogo(); 15 | email: string = ''; 16 | password: string = ''; 17 | passwordConfirmation: string = ''; 18 | error: string = null; 19 | 20 | constructor(public navigation: NavigationService, private users: UsersService) { } 21 | 22 | ngOnInit() { 23 | } 24 | 25 | onSubmit(event: Event, submitButton: HTMLButtonElement|any) { 26 | const form = event.target as any; 27 | form.isSubmitted = true; 28 | if (form.checkValidity() && this.password === this.passwordConfirmation) { 29 | const startLoading = () => { 30 | submitButton.isDisabled = true; 31 | submitButton.isLoading = true; 32 | }; 33 | const stopLoading = () => { 34 | submitButton.isDisabled = false; 35 | submitButton.isLoading = false; 36 | }; 37 | startLoading(); 38 | // Register admin 39 | this.users.register({ 40 | firstName: 'Super', 41 | lastName: 'Admin', 42 | email: this.email, 43 | password: this.password, 44 | role: UserRole.Administrator, 45 | birthDate: null, 46 | bio: null 47 | }).then(() => { 48 | this.navigation.redirectTo(`login?email=${this.email}&password=${this.password}`); 49 | }).catch((error: Error) => { 50 | this.error = error.message; 51 | }).finally(() => { 52 | stopLoading(); 53 | }); 54 | } 55 | } 56 | 57 | dismissError(event: Event) { 58 | event.preventDefault(); 59 | event.stopPropagation(); 60 | this.error = null; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/settings/settings.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/settings/settings.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/settings/settings.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { SettingsComponent } from './settings.component'; 4 | 5 | describe('SettingsComponent', () => { 6 | let component: SettingsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ SettingsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(SettingsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/settings/settings.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { I18nService } from '../../services/i18n.service'; 3 | import { AlertService } from '../../services/alert.service'; 4 | import { SettingsService } from '../../services/settings.service'; 5 | import { NavigationService } from '../../services/navigation.service'; 6 | import { Language } from '../../models/language.model'; 7 | 8 | @Component({ 9 | selector: 'fa-settings', 10 | templateUrl: './settings.component.html', 11 | styleUrls: ['./settings.component.css'] 12 | }) 13 | export class SettingsComponent implements OnInit { 14 | 15 | i18nLanguage: string; 16 | i18nKey: string; 17 | 18 | constructor( 19 | public settings: SettingsService, 20 | public navigation: NavigationService, 21 | private i18n: I18nService, 22 | private alert: AlertService 23 | ) { } 24 | 25 | ngOnInit() { 26 | } 27 | 28 | saveChanges(event: Event) { 29 | event.preventDefault(); 30 | this.settings.save(); 31 | this.i18n.setLanguage(this.settings.language); 32 | this.alert.success(this.i18n.get('SettingsSaved'), true); 33 | window.location.reload(); 34 | } 35 | 36 | onI18nLanguageInput() { 37 | if (!this.i18nKey || this.i18nKey.length < 2) { 38 | this.i18nKey = this.i18nLanguage.substr(0, 2).toLowerCase(); 39 | } 40 | } 41 | 42 | addSupportedLanguage() { 43 | this.settings.supportedLanguages.push({ 44 | label: this.i18nLanguage, 45 | key: this.i18nKey, 46 | isActive: true, 47 | isRemovable: true 48 | }); 49 | this.i18nLanguage = this.i18nKey = ''; 50 | } 51 | 52 | removeSupportedLanguage(lang: Language, index: number) { 53 | const activeSupportedLanguages = this.settings.getActiveSupportedLanguages(); 54 | if ((activeSupportedLanguages && activeSupportedLanguages.length > 1) || !lang.isActive) { 55 | this.settings.supportedLanguages.splice(index, 1); 56 | } 57 | } 58 | 59 | onSupportedLanguageCheckboxClick(event: Event, lang: Language) { 60 | const activeSupportedLanguages = this.settings.getActiveSupportedLanguages(); 61 | if (activeSupportedLanguages.length < 2 && lang.isActive) { 62 | event.preventDefault(); 63 | } 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/alert/alert.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/shared/alert/alert.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/alert/alert.component.html: -------------------------------------------------------------------------------- 1 |
2 | 8 |
9 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/alert/alert.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AlertComponent } from './alert.component'; 4 | 5 | describe('AlertComponent', () => { 6 | let component: AlertComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AlertComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AlertComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/alert/alert.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { AlertService } from '../../../services/alert.service'; 3 | 4 | @Component({ 5 | selector: 'fa-alert', 6 | templateUrl: './alert.component.html', 7 | styleUrls: ['./alert.component.css'] 8 | }) 9 | export class AlertComponent implements OnInit { 10 | 11 | constructor(public alert: AlertService) { } 12 | 13 | ngOnInit() { 14 | } 15 | 16 | dismissAlert(event: Event) { 17 | event.preventDefault(); 18 | event.stopPropagation(); 19 | this.alert.clear(); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/button-group/button-group.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/shared/button-group/button-group.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/button-group/button-group.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 | 6 | 7 |
8 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/button-group/button-group.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ButtonGroupComponent } from './button-group.component'; 4 | 5 | describe('ButtonGroupComponent', () => { 6 | let component: ButtonGroupComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ButtonGroupComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ButtonGroupComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/button-group/button-group.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'fa-button-group', 5 | templateUrl: './button-group.component.html', 6 | styleUrls: ['./button-group.component.css'] 7 | }) 8 | export class ButtonGroupComponent implements OnInit { 9 | 10 | @Input() value: string; 11 | @Input() options: string[]; 12 | @Input() values: string[] = []; 13 | @Output() valueChange: EventEmitter = new EventEmitter(); 14 | 15 | constructor() { } 16 | 17 | ngOnInit() { 18 | } 19 | 20 | isActive(option: string, index: number) { 21 | return this.value === this.getValue(option, index); 22 | } 23 | 24 | getValue(option: string, index: number) { 25 | return this.values && this.values[index] ? this.values[index] : option; 26 | } 27 | 28 | setValue(option: string, index: number) { 29 | const value = this.getValue(option, index); 30 | this.value = value; 31 | this.valueChange.emit(value); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/footer/footer.component.css: -------------------------------------------------------------------------------- 1 | .heart { 2 | color: #e25555; 3 | } 4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/footer/footer.component.html: -------------------------------------------------------------------------------- 1 | 17 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/footer/footer.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FooterComponent } from './footer.component'; 4 | 5 | describe('FooterComponent', () => { 6 | let component: FooterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FooterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FooterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { NavigationService } from '../../../services/navigation.service'; 3 | 4 | @Component({ 5 | selector: 'fa-footer', 6 | templateUrl: './footer.component.html', 7 | styleUrls: ['./footer.component.css'] 8 | }) 9 | export class FooterComponent implements OnInit { 10 | 11 | constructor(public navigation: NavigationService) { } 12 | 13 | ngOnInit() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/layout/layout.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/shared/layout/layout.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/layout/layout.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 |
11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 |
20 |
21 |
22 |
23 | 24 | 25 |
26 | 27 |
28 |
29 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/layout/layout.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LayoutComponent } from './layout.component'; 4 | 5 | describe('LayoutComponent', () => { 6 | let component: LayoutComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LayoutComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LayoutComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/layout/layout.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, AfterViewInit } from '@angular/core'; 2 | import { SettingsService } from '../../../services/settings.service'; 3 | import { initLayout } from '../../../helpers/layout.helper'; 4 | 5 | @Component({ 6 | selector: 'fa-layout', 7 | templateUrl: './layout.component.html', 8 | styleUrls: ['./layout.component.css'] 9 | }) 10 | export class LayoutComponent implements OnInit, AfterViewInit { 11 | 12 | constructor(public settings: SettingsService) { } 13 | 14 | ngOnInit() { 15 | } 16 | 17 | ngAfterViewInit() { 18 | initLayout(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/loading-indicator/loading-indicator.component.css: -------------------------------------------------------------------------------- 1 | .centered { 2 | position: absolute; 3 | left: 50%; 4 | top: 50%; 5 | transform: translate(-50%, -50%); 6 | z-index: 1; 7 | } 8 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/loading-indicator/loading-indicator.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/loading-indicator/loading-indicator.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoadingIndicatorComponent } from './loading-indicator.component'; 4 | 5 | describe('LoadingIndicatorComponent', () => { 6 | let component: LoadingIndicatorComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoadingIndicatorComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoadingIndicatorComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/loading-indicator/loading-indicator.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'fa-loading-indicator', 5 | templateUrl: './loading-indicator.component.html', 6 | styleUrls: ['./loading-indicator.component.css'] 7 | }) 8 | export class LoadingIndicatorComponent implements OnInit { 9 | 10 | @Input() show: boolean = true; 11 | @Input() icon: string = 'fas fa-circle-notch'; 12 | @Input() size: string = '2x'; 13 | @Input() animation: string = 'spin'; 14 | @Input() center: boolean = false; 15 | 16 | constructor() { } 17 | 18 | ngOnInit() { 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/navbar/navbar.component.css: -------------------------------------------------------------------------------- 1 | .dropdown-toggle::after { 2 | vertical-align: middle; 3 | } 4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/navbar/navbar.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 43 | 44 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/navbar/navbar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { NavbarComponent } from './navbar.component'; 4 | 5 | describe('NavbarComponent', () => { 6 | let component: NavbarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ NavbarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(NavbarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/navbar/navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | import { AuthService } from '../../../services/auth.service'; 3 | import { NavigationService } from '../../../services/navigation.service'; 4 | import { toggleSidebar } from '../../../helpers/layout.helper'; 5 | import { getLogo, getDefaultAvatar } from '../../../helpers/assets.helper'; 6 | import { CurrentUserService } from '../../../services/current-user.service'; 7 | 8 | @Component({ 9 | selector: 'fa-navbar', 10 | templateUrl: './navbar.component.html', 11 | styleUrls: ['./navbar.component.css'] 12 | }) 13 | export class NavbarComponent implements OnInit { 14 | 15 | @Input() isSticky: boolean = true; 16 | @Input() isCentered: boolean = false; 17 | @Input() showBrand: boolean = false; 18 | logo: string = getLogo(); 19 | defaultAvatar = getDefaultAvatar(); 20 | 21 | constructor( 22 | public currentUser: CurrentUserService, 23 | public navigation: NavigationService, 24 | private auth: AuthService 25 | ) { } 26 | 27 | ngOnInit() { 28 | } 29 | 30 | getUserName(): string { 31 | return this.currentUser.data ? `${this.currentUser.data.firstName} ${this.currentUser.data.lastName}` : ( 32 | this.auth.firebaseUser ? this.auth.firebaseUser.providerData[0].displayName || this.auth.firebaseUser.providerData[0].email : 'unknown' 33 | ); 34 | } 35 | 36 | toggleSidebar(event: Event) { 37 | event.preventDefault(); 38 | event.stopPropagation(); 39 | toggleSidebar(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/sidebar/sidebar.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/shared/sidebar/sidebar.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/sidebar/sidebar.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 23 | 24 | 25 |
26 |
27 |
28 |
29 | 30 |
31 |
32 |
33 |
34 |
35 | 36 | 37 | 65 | 66 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/sidebar/sidebar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { SidebarComponent } from './sidebar.component'; 4 | 5 | describe('SidebarComponent', () => { 6 | let component: SidebarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ SidebarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(SidebarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/shared/sidebar/sidebar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, AfterViewInit, Input } from '@angular/core'; 2 | import { NavigationService } from '../../../services/navigation.service'; 3 | import { initDropdown, toggleSidebar } from '../../../helpers/layout.helper'; 4 | import { getLogo } from '../../../helpers/assets.helper'; 5 | import { CurrentUserService } from '../../../services/current-user.service'; 6 | import { SidebarItem } from '../../../models/sidebar-item.model'; 7 | 8 | @Component({ 9 | selector: 'fa-sidebar', 10 | templateUrl: './sidebar.component.html', 11 | styleUrls: ['./sidebar.component.css'] 12 | }) 13 | export class SidebarComponent implements OnInit, AfterViewInit { 14 | 15 | @Input() style: string = 'expanded'; 16 | logo: string = getLogo(); 17 | items: SidebarItem[] = [ 18 | // Dashboard 19 | { 20 | label: 'Dashboard', 21 | icon: '', 22 | routerLink: this.navigation.getRouterLink('dashboard') 23 | }, 24 | // Pages 25 | { 26 | label: 'Pages', 27 | icon: 'insert_drive_file', 28 | isActive: this.isActive(['pages', 'list'], ['pages', 'add'], ['pages', 'edit'], ['pages', 'translate']), 29 | childrens: [ 30 | { 31 | label: 'List', 32 | routerLink: this.navigation.getRouterLink('pages', 'list') 33 | }, 34 | { 35 | label: 'Add', 36 | routerLink: this.navigation.getRouterLink('pages', 'add') 37 | } 38 | ] 39 | }, 40 | // Posts 41 | { 42 | label: 'Posts', 43 | icon: 'description', 44 | isActive: this.isActive(['posts', 'list'], ['posts', 'add'], ['posts', 'edit'], ['posts', 'translate'], ['posts', 'categories']), 45 | childrens: [ 46 | { 47 | label: 'List', 48 | routerLink: this.navigation.getRouterLink('posts', 'list') 49 | }, 50 | { 51 | label: 'Add', 52 | routerLink: this.navigation.getRouterLink('posts', 'add') 53 | }, 54 | { 55 | label: 'Categories', 56 | routerLink: this.navigation.getRouterLink('posts', 'categories') 57 | } 58 | ] 59 | }, 60 | // Users 61 | { 62 | label: 'Users', 63 | icon: 'person', 64 | isActive: this.isActive(['users', 'list'], ['users', 'add'], ['users', 'edit'], ['users', 'profile']), 65 | isHidden: () => !this.currentUser.isAdmin(), 66 | childrens: [ 67 | { 68 | label: 'List', 69 | routerLink: this.navigation.getRouterLink('users', 'list') 70 | }, 71 | { 72 | label: 'Add', 73 | routerLink: this.navigation.getRouterLink('users', 'add') 74 | } 75 | ] 76 | }, 77 | // Translations 78 | { 79 | label: 'Translations', 80 | icon: 'language', 81 | routerLink: this.navigation.getRouterLink('translations') 82 | }, 83 | // { 84 | // label: 'Menus', 85 | // icon: 'menu', 86 | // routerLink: this.navigation.getRouterLink('menus') 87 | // }, 88 | // { 89 | // label: 'Comments', 90 | // icon: 'comment', 91 | // isActive: this.isActive(['comments', 'list'], ['comments', 'add'], ['comments', 'edit']), 92 | // childrens: [ 93 | // { 94 | // label: 'List', 95 | // routerLink: this.navigation.getRouterLink('comments', 'list') 96 | // }, 97 | // { 98 | // label: 'Add', 99 | // routerLink: this.navigation.getRouterLink('comments', 'add') 100 | // } 101 | // ] 102 | // }, 103 | // { 104 | // label: 'Media', 105 | // icon: '', 106 | // isActive: this.isActive(['media', 'list'], ['media', 'add'], ['media', 'edit']), 107 | // childrens: [ 108 | // { 109 | // label: 'List', 110 | // routerLink: this.navigation.getRouterLink('media', 'list') 111 | // }, 112 | // { 113 | // label: 'Add', 114 | // routerLink: this.navigation.getRouterLink('media', 'add') 115 | // } 116 | // ] 117 | // }, 118 | ]; 119 | 120 | constructor(public navigation: NavigationService, private currentUser: CurrentUserService) { } 121 | 122 | ngOnInit() { 123 | } 124 | 125 | ngAfterViewInit() { 126 | initDropdown(); 127 | } 128 | 129 | private isRouteActive(...path: string[]) { 130 | const link = this.navigation.getRouterLink(...path).join('/'); 131 | //console.log(link); 132 | return this.navigation.router.isActive(link, false); 133 | } 134 | 135 | private isActive(...routes: any[]) { 136 | let isActive = false; 137 | routes.forEach((path: string[]) => { 138 | if (this.isRouteActive(...path)) { 139 | isActive = true; 140 | } 141 | }); 142 | return isActive; 143 | } 144 | 145 | toggle() { 146 | toggleSidebar(); 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/translations/translations.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/translations/translations.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/translations/translations.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { TranslationsComponent } from './translations.component'; 4 | 5 | describe('TranslationsComponent', () => { 6 | let component: TranslationsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ TranslationsComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(TranslationsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/translations/translations.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy, ViewChild, AfterViewInit } from '@angular/core'; 2 | import { SettingsService } from '../../services/settings.service'; 3 | import { Language } from '../../models/language.model'; 4 | import { AlertService } from '../../services/alert.service'; 5 | import { I18nService } from '../../services/i18n.service'; 6 | import { Observable, Subject, Subscription } from 'rxjs'; 7 | import { DataTableDirective } from 'angular-datatables'; 8 | import { refreshDataTable } from '../../helpers/datatables.helper'; 9 | import { TranslationData } from '../../models/collections/translation.model'; 10 | import { TranslationsService } from '../../services/collections/translations.service'; 11 | import { initPopover } from '../../helpers/layout.helper'; 12 | 13 | @Component({ 14 | selector: 'fa-translations', 15 | templateUrl: './translations.component.html', 16 | styleUrls: ['./translations.component.css'] 17 | }) 18 | export class TranslationsComponent implements OnInit, OnDestroy, AfterViewInit { 19 | 20 | key: string; 21 | value: string; 22 | language: string; 23 | languages: Language[]; 24 | allLanguages: Language[] = []; 25 | allTranslations: Observable; 26 | selectedTranslation: TranslationData = null; 27 | @ViewChild(DataTableDirective, {static : false}) private dataTableElement: DataTableDirective; 28 | dataTableOptions: DataTables.Settings|any = { 29 | responsive: true, 30 | aaSorting: [] 31 | }; 32 | dataTableTrigger: Subject = new Subject(); 33 | private subscription: Subscription = new Subscription(); 34 | 35 | constructor( 36 | private settings: SettingsService, 37 | private translations: TranslationsService, 38 | private alert: AlertService, 39 | private i18n: I18nService 40 | ) { } 41 | 42 | ngOnInit() { 43 | // Get active languages 44 | this.languages = this.settings.getActiveSupportedLanguages(); 45 | this.language = this.languages[0].key; 46 | // Get all languages 47 | this.settings.supportedLanguages.forEach((language: Language) => { 48 | this.allLanguages[language.key] = language; 49 | }); 50 | // Get all translations 51 | this.allTranslations = this.translations.getAll(); 52 | this.subscription.add( 53 | this.allTranslations.subscribe((translations: TranslationData[]) => { 54 | // console.log(translations); 55 | // Refresh datatable on data change 56 | refreshDataTable(this.dataTableElement, this.dataTableTrigger, true); 57 | }) 58 | ); 59 | } 60 | 61 | ngOnDestroy() { 62 | this.dataTableTrigger.unsubscribe(); 63 | this.subscription.unsubscribe(); 64 | } 65 | 66 | ngAfterViewInit() { 67 | initPopover('#translations-tooltip'); 68 | } 69 | 70 | addTranslation(event: Event) { 71 | const addButton = event.target as any; 72 | addButton.disabled = true; 73 | // Check if translation key already exists 74 | this.translations.keyExists(this.key, this.language).then((exists: boolean) => { 75 | if (exists) { 76 | // Warn user about existing translation key 77 | const lang = this.i18n.get(this.allLanguages[this.language].label); 78 | this.alert.warning(this.i18n.get('TranslationKeyAlreadyExists', { key: this.key, lang: lang }), false, 5000); 79 | addButton.disabled = false; 80 | } else { 81 | this.translations.add({ 82 | key: this.key, 83 | value: this.value, 84 | lang: this.language 85 | }).then(() => { 86 | this.alert.success(this.i18n.get('TranslationAdded'), false, 5000); 87 | }).catch((error: Error) => { 88 | this.alert.error(error.message); 89 | }).finally(() => { 90 | this.key = this.value = ''; 91 | }); 92 | } 93 | }); 94 | } 95 | 96 | deleteTranslation(translation: TranslationData) { 97 | this.translations.delete(translation.key, translation.lang).then(() => { 98 | this.alert.success(this.i18n.get('TranslationDeleted', { key: translation.key }), false, 5000); 99 | }).catch((error: Error) => { 100 | this.alert.error(error.message); 101 | }); 102 | } 103 | 104 | editTranslation(translation: TranslationData) { 105 | this.translations.edit(translation).then(() => { 106 | this.alert.success(this.i18n.get('TranslationSaved', { key: translation.key }), false, 5000); 107 | }).catch((error: Error) => { 108 | this.alert.error(error.message); 109 | }); 110 | } 111 | 112 | setSelectedTranslation(translation: TranslationData) { 113 | this.selectedTranslation = Object.assign({}, translation); 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/add/users-add.component.css: -------------------------------------------------------------------------------- 1 | .edit-user-details__avatar img { 2 | height: 120px; 3 | } 4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/add/users-add.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UsersAddComponent } from './users-add.component'; 4 | 5 | describe('UsersAddComponent', () => { 6 | let component: UsersAddComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UsersAddComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UsersAddComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/add/users-add.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { getDefaultAvatar } from '../../../helpers/assets.helper'; 3 | import { UserRole } from '../../../models/collections/user.model'; 4 | import { UsersService } from '../../../services/collections/users.service'; 5 | import { AlertService } from '../../../services/alert.service'; 6 | import { I18nService } from '../../../services/i18n.service'; 7 | import { NavigationService } from '../../../services/navigation.service'; 8 | 9 | @Component({ 10 | selector: 'fa-users-add', 11 | templateUrl: './users-add.component.html', 12 | styleUrls: ['./users-add.component.css'] 13 | }) 14 | export class UsersAddComponent implements OnInit { 15 | 16 | firstName: string; 17 | lastName: string; 18 | email: string; 19 | password: string; 20 | birthDate: string; 21 | role: UserRole; 22 | allRoles: object|any = {}; 23 | bio: string; 24 | private avatar: File; 25 | avatarSrc: string|ArrayBuffer; 26 | 27 | constructor( 28 | private users: UsersService, 29 | private alert: AlertService, 30 | private i18n: I18nService, 31 | private navigation: NavigationService 32 | ) { } 33 | 34 | ngOnInit() { 35 | this.allRoles = this.users.getAllRoles(); 36 | this.role = UserRole.Guest; 37 | this.avatar = null; 38 | this.avatarSrc = getDefaultAvatar(); 39 | this.bio = null; 40 | } 41 | 42 | onAvatarChange(event: Event) { 43 | this.avatar = (event.target as HTMLInputElement).files[0]; 44 | const reader = new FileReader(); 45 | reader.onload = () => { 46 | this.avatarSrc = reader.result; 47 | }; 48 | reader.readAsDataURL(this.avatar); 49 | } 50 | 51 | addUser(event: Event, form: HTMLFormElement) { 52 | form.isSubmitted = true; 53 | if (form.checkValidity()) { 54 | const target = event.target as any; 55 | const startLoading = () => { 56 | target.isDisabled = true; 57 | target.isLoading = true; 58 | }; 59 | const stopLoading = () => { 60 | target.isDisabled = false; 61 | target.isLoading = false; 62 | }; 63 | startLoading(); 64 | // Add user 65 | this.users.add({ 66 | firstName: this.firstName, 67 | lastName: this.lastName, 68 | email: this.email, 69 | password: this.password, 70 | birthDate: this.birthDate ? new Date(this.birthDate).getTime() : null, 71 | role: this.role, 72 | bio: this.bio, 73 | avatar: this.avatar 74 | }).then(() => { 75 | this.alert.success(this.i18n.get('UserAdded'), false, 5000, true); 76 | this.navigation.redirectTo('users', 'list'); 77 | }).catch((error: Error) => { 78 | this.alert.error(error.message); 79 | }).finally(() => { 80 | stopLoading(); 81 | }); 82 | } 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/edit/users-edit.component.css: -------------------------------------------------------------------------------- 1 | .edit-user-details__avatar { 2 | box-shadow: none; 3 | } 4 | 5 | .edit-user-details__avatar img { 6 | height: 120px; 7 | } 8 | 9 | .list-group-item { 10 | margin-bottom: 0; 11 | } 12 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/edit/users-edit.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UsersEditComponent } from './users-edit.component'; 4 | 5 | describe('UsersEditComponent', () => { 6 | let component: UsersEditComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UsersEditComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UsersEditComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/edit/users-edit.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { UserRole, User } from '../../../models/collections/user.model'; 3 | import { Subscription } from 'rxjs'; 4 | import { UsersService } from '../../../services/collections/users.service'; 5 | import { I18nService } from '../../../services/i18n.service'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { ActivatedRoute } from '@angular/router'; 8 | import { take } from 'rxjs/operators'; 9 | import { NavigationService } from '../../../services/navigation.service'; 10 | 11 | @Component({ 12 | selector: 'fa-users-edit', 13 | templateUrl: './users-edit.component.html', 14 | styleUrls: ['./users-edit.component.css'] 15 | }) 16 | export class UsersEditComponent implements OnInit, OnDestroy { 17 | 18 | id: string; 19 | firstName: string; 20 | lastName: string; 21 | email: string; 22 | password: string; 23 | birthDate: string; 24 | role: UserRole; 25 | allRoles: object|any = {}; 26 | bio: string; 27 | private avatar: File; 28 | avatarSrc: string|ArrayBuffer; 29 | private subscription: Subscription = new Subscription(); 30 | userData: User; // used to keep track of old user data 31 | 32 | constructor( 33 | private users: UsersService, 34 | private i18n: I18nService, 35 | private alert: AlertService, 36 | private route: ActivatedRoute, 37 | public navigation: NavigationService 38 | ) { } 39 | 40 | ngOnInit() { 41 | this.allRoles = this.users.getAllRoles(); 42 | this.subscription.add( 43 | this.route.params.subscribe((params: { id: string }) => { 44 | // console.log(params); 45 | this.users.get(params.id).pipe(take(1)).toPromise().then((user: User) => { 46 | // console.log(user); 47 | if (user) { 48 | this.userData = user; 49 | this.id = params.id; 50 | this.firstName = user.firstName; 51 | this.lastName = user.lastName; 52 | this.email = user.email; 53 | this.password = user.password; 54 | this.birthDate = user.birthDate ? new Date(user.birthDate).toISOString().slice(0, 10) : null; 55 | this.role = user.role; 56 | this.bio = user.bio; 57 | this.avatar = null; 58 | this.subscription.add( 59 | this.users.getAvatarUrl(user.avatar as string).subscribe((imageUrl: string) => { 60 | this.avatarSrc = imageUrl; 61 | }) 62 | ); 63 | } else { 64 | this.navigation.redirectTo('users', 'list'); 65 | } 66 | }); 67 | }) 68 | ); 69 | } 70 | 71 | ngOnDestroy() { 72 | this.subscription.unsubscribe(); 73 | } 74 | 75 | onAvatarChange(event: Event) { 76 | this.avatar = (event.target as HTMLInputElement).files[0]; 77 | const reader = new FileReader(); 78 | reader.onload = () => { 79 | this.avatarSrc = reader.result; 80 | }; 81 | reader.readAsDataURL(this.avatar); 82 | } 83 | 84 | updateUser(event: Event, form: HTMLFormElement) { 85 | form.isSubmitted = true; 86 | if (form.checkValidity()) { 87 | const target = event.target as any; 88 | const startLoading = () => { 89 | target.isDisabled = true; 90 | target.isLoading = true; 91 | }; 92 | const stopLoading = () => { 93 | target.isDisabled = false; 94 | target.isLoading = false; 95 | }; 96 | startLoading(); 97 | // Edit user 98 | const data: User = { 99 | firstName: this.firstName, 100 | lastName: this.lastName, 101 | email: this.email, 102 | password: this.password, 103 | birthDate: this.birthDate ? new Date(this.birthDate).getTime() : null, 104 | role: this.role, 105 | bio: this.bio 106 | }; 107 | if (this.avatar) { 108 | data.avatar = this.avatar; 109 | } 110 | this.users.edit(this.id, data, { 111 | email: this.userData.email, 112 | password: this.userData.password 113 | }).then(() => { 114 | this.userData = {...this.userData, ...data}; // override old user data 115 | this.alert.success(this.i18n.get('UserUpdated'), false, 5000); 116 | }).catch((error: Error) => { 117 | this.alert.error(error.message); 118 | }).finally(() => { 119 | stopLoading(); 120 | }); 121 | } 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/list/users-list.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/projects/fire-admin/src/lib/components/users/list/users-list.component.css -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/list/users-list.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 |
12 |
13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 38 | 39 | 40 | 43 | 44 | 45 | 50 | 60 | 61 | 62 |
{{ 'UserName' | translate }}{{ 'Email' | translate }}{{ 'BirthDate' | translate }}{{ 'Role' | translate }}{{ 'CreatedAt' | translate }}{{ 'UpdatedAt' | translate }}{{ 'CreatedBy' | translate }}{{ 'Actions' | translate }}
32 | 33 | 35 | {{ user.firstName + ' ' + user.lastName }} 36 | {{ allRoles[user.role] | translate }} 37 | {{ user.email }}{{ user.birthDate | shortdate }} 41 | {{ allRoles[user.role] | translate }} 42 | {{ user.createdAt | datetime }}{{ user.updatedAt | datetime }} 46 | 47 | {{ creator }} 48 | 49 | 51 |
52 | 55 | 58 |
59 |
63 |
64 |
65 |
66 |
67 |
68 | 69 | 70 | 87 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/list/users-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UsersListComponent } from './users-list.component'; 4 | 5 | describe('UsersListComponent', () => { 6 | let component: UsersListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UsersListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UsersListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/list/users-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core'; 2 | import { Observable, Subject, Subscription } from 'rxjs'; 3 | import { User } from '../../../models/collections/user.model'; 4 | import { DataTableDirective } from 'angular-datatables'; 5 | import { UsersService } from '../../../services/collections/users.service'; 6 | import { AlertService } from '../../../services/alert.service'; 7 | import { I18nService } from '../../../services/i18n.service'; 8 | import { ActivatedRoute } from '@angular/router'; 9 | import { NavigationService } from '../../../services/navigation.service'; 10 | import { map, takeUntil, skip } from 'rxjs/operators'; 11 | import { refreshDataTable } from '../../../helpers/datatables.helper'; 12 | import { CurrentUserService } from '../../../services/current-user.service'; 13 | 14 | @Component({ 15 | selector: 'fa-users-list', 16 | templateUrl: './users-list.component.html', 17 | styleUrls: ['./users-list.component.css'] 18 | }) 19 | export class UsersListComponent implements OnInit, OnDestroy { 20 | 21 | allUsers: Observable; 22 | selectedUser: User = null; 23 | @ViewChild(DataTableDirective, {static : false}) private dataTableElement: DataTableDirective; 24 | dataTableOptions: DataTables.Settings|any = { 25 | responsive: true, 26 | aaSorting: [] 27 | }; 28 | dataTableTrigger: Subject = new Subject(); 29 | private subscription: Subscription = new Subscription(); 30 | allRoles: object|any = {}; 31 | private routeParamsChange: Subject = new Subject(); 32 | isLoading: boolean = true; 33 | 34 | constructor( 35 | private users: UsersService, 36 | private alert: AlertService, 37 | private i18n: I18nService, 38 | private route: ActivatedRoute, 39 | private currentUser: CurrentUserService, 40 | public navigation: NavigationService 41 | ) { } 42 | 43 | ngOnInit() { 44 | // Get all roles 45 | this.allRoles = this.users.getAllRoles(); 46 | // Get route params 47 | this.subscription.add( 48 | this.route.params.subscribe((params: { role: string }) => { 49 | this.routeParamsChange.next(); 50 | this.isLoading = true; 51 | // Get all users 52 | this.allUsers = this.users.getAll().pipe( 53 | //skip(this.currentUser.data ? 1 : 0), // workaround to skip first emitted value when currentUser subscription is running (not working when we only have 1 user) 54 | map((users: User[]) => { 55 | // Filter by role 56 | if (params.role) { 57 | users = users.filter((user: User) => user.role === params.role); 58 | } 59 | // Get avatar & creator 60 | users.forEach((user: User) => { 61 | user.avatar = { 62 | path: user.avatar, // we need to keep track of avatar path for delete purpose 63 | url: this.users.getAvatarUrl(user.avatar as string) 64 | }; 65 | if (user.createdBy) { 66 | user.creator = this.users.getFullName(user.createdBy); 67 | } 68 | }); 69 | return users.sort((a: User, b: User) => b.createdAt - a.createdAt); 70 | }), 71 | takeUntil(this.routeParamsChange) 72 | ); 73 | this.subscription.add( 74 | this.allUsers.subscribe((users: User[]) => { 75 | // console.log(users); 76 | // Refresh datatable on data change 77 | refreshDataTable(this.dataTableElement, this.dataTableTrigger); 78 | this.isLoading = false; 79 | }) 80 | ); 81 | }) 82 | ); 83 | } 84 | 85 | ngOnDestroy() { 86 | this.dataTableTrigger.unsubscribe(); 87 | this.subscription.unsubscribe(); 88 | this.routeParamsChange.next(); 89 | } 90 | 91 | deleteUser(user: User) { 92 | this.users.delete(user.id, { 93 | email: user.email, 94 | password: user.password, 95 | avatar: (user.avatar as any).path 96 | }).then(() => { 97 | this.alert.success(this.i18n.get('UserDeleted', { name: `${user.firstName} ${user.lastName}` }), false, 5000); 98 | }).catch((error: Error) => { 99 | this.alert.error(error.message); 100 | }); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/profile/users-profile.component.css: -------------------------------------------------------------------------------- 1 | .user-details__avatar img { 2 | height: 100px; 3 | } 4 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/components/users/profile/users-profile.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { UsersProfileComponent } from './users-profile.component'; 4 | 5 | describe('UsersProfileComponent', () => { 6 | let component: UsersProfileComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ UsersProfileComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(UsersProfileComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/fire-admin.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FireAdminComponent } from './fire-admin.component'; 4 | 5 | describe('FireAdminComponent', () => { 6 | let component: FireAdminComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FireAdminComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FireAdminComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/fire-admin.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, ViewEncapsulation, OnDestroy } from '@angular/core'; 2 | import { AlertService } from './services/alert.service'; 3 | import { CurrentUserService } from './services/current-user.service'; 4 | 5 | @Component({ 6 | selector: 'fa-root', 7 | template: ``, 8 | styleUrls: ['./fire-admin.component.css'], 9 | encapsulation: ViewEncapsulation.None 10 | }) 11 | export class FireAdminComponent implements OnInit, OnDestroy { 12 | 13 | constructor(private alert: AlertService, private currentUser: CurrentUserService) { } 14 | 15 | ngOnInit() { 16 | } 17 | 18 | ngOnDestroy() { 19 | this.currentUser.unsubscribe(); 20 | } 21 | 22 | clearAlert() { 23 | if (! this.alert.isPersistent) { 24 | this.alert.clear(); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/fire-admin.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { FireAdminService } from './fire-admin.service'; 4 | 5 | describe('FireAdminService', () => { 6 | beforeEach(() => TestBed.configureTestingModule({})); 7 | 8 | it('should be created', () => { 9 | const service: FireAdminService = TestBed.get(FireAdminService); 10 | expect(service).toBeTruthy(); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/fire-admin.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@angular/core'; 2 | import { FirebaseOptionsToken } from '@angular/fire'; 3 | 4 | @Injectable({ 5 | providedIn: 'root' 6 | }) 7 | export class FireAdminService { 8 | 9 | constructor(@Inject(FirebaseOptionsToken) private firebaseConfig) { } 10 | 11 | static getFirebaseConfig(self: FireAdminService) { 12 | //console.log(self.firebaseConfig); 13 | return self.firebaseConfig; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/guards/auth.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | import { AuthService } from '../services/auth.service'; 4 | import { NavigationService } from '../services/navigation.service'; 5 | 6 | @Injectable() 7 | export class AuthGuard implements CanActivate { 8 | 9 | constructor(private auth: AuthService, private navigation: NavigationService) { } 10 | 11 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { 12 | return new Promise(async (resolve, reject) => { 13 | const isSignedIn = await this.auth.isSignedIn(); 14 | if (! isSignedIn) { 15 | // const rootPath = state.url.slice(0, state.url.indexOf(route.url[route.url.length - 1].path)); 16 | // this.navigation.setRootPath(rootPath); 17 | this.navigation.redirectTo('login'); 18 | resolve(false); 19 | } else { 20 | resolve(true); 21 | } 22 | }); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/guards/login.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | import { AuthService } from '../services/auth.service'; 4 | import { NavigationService } from '../services/navigation.service'; 5 | import { ConfigService } from '../services/collections/config.service'; 6 | 7 | @Injectable() 8 | export class LoginGuard implements CanActivate { 9 | 10 | constructor(private auth: AuthService, private navigation: NavigationService, private config: ConfigService) { } 11 | 12 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { 13 | return new Promise(async (resolve, reject) => { 14 | const isSignedIn = await this.auth.isSignedIn(); 15 | if (isSignedIn) { 16 | // const rootPath = state.url.slice(0, state.url.indexOf(route.url[route.url.length - 1].path)); 17 | // this.navigation.setRootPath(rootPath); 18 | this.navigation.redirectTo('dashboard'); 19 | resolve(false); 20 | } else { 21 | const registrationEnabled = await this.config.isRegistrationEnabled(); 22 | //console.log(registrationEnabled); 23 | if (!registrationEnabled) { 24 | resolve(true); 25 | } else { 26 | this.navigation.redirectTo('register'); 27 | resolve(false); 28 | } 29 | } 30 | }); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/guards/register.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | import { NavigationService } from '../services/navigation.service'; 4 | import { ConfigService } from '../services/collections/config.service'; 5 | 6 | @Injectable() 7 | export class RegisterGuard implements CanActivate { 8 | 9 | constructor(private navigation: NavigationService, private config: ConfigService) { } 10 | 11 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { 12 | return new Promise(async (resolve, reject) => { 13 | const registrationEnabled = await this.config.isRegistrationEnabled(); 14 | //console.log(registrationEnabled); 15 | if (registrationEnabled) { 16 | resolve(true); 17 | } else { 18 | this.navigation.redirectTo('login'); 19 | resolve(false); 20 | } 21 | }); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/guards/user.guard.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router'; 3 | import { NavigationService } from '../services/navigation.service'; 4 | import { User, UserRole } from '../models/collections/user.model'; 5 | import { CurrentUserService } from '../services/current-user.service'; 6 | 7 | @Injectable() 8 | export class UserGuard implements CanActivate { 9 | 10 | constructor(private currentUser: CurrentUserService, private navigation: NavigationService) { } 11 | 12 | canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { 13 | return new Promise(async (resolve, reject) => { 14 | const user: User = await this.currentUser.get(); 15 | //console.log(user); 16 | if (user.role === UserRole.Administrator) { 17 | resolve(true); 18 | } else { 19 | //console.log(route); 20 | // A non admin user can only consult its own profile 21 | if (route.url[0].path === 'profile' && route.params['id'] === user.id) { 22 | resolve(true); 23 | } 24 | // After admin, only editors are allowed to modify their own informations 25 | else if (user.role === UserRole.Editor && route.url[0].path === 'edit' && route.params['id'] === user.id) { 26 | resolve(true); 27 | } 28 | // Redirect to dashboard on any other attempts 29 | else { 30 | this.navigation.redirectTo('dashboard'); 31 | resolve(false); 32 | } 33 | } 34 | }); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/charts.helper.ts: -------------------------------------------------------------------------------- 1 | declare var Chart: any; 2 | 3 | export function initPieChart(selector: string, data: any[], labels: any[], backgroundColor: string[] = [], hoverBorderColor: string = "#ffffff") { 4 | let canvas = document.querySelector(selector); 5 | if (backgroundColor.length === 0) { 6 | backgroundColor = [ 7 | "rgba(0,123,255,0.9)", 8 | "rgba(0,123,255,0.5)", 9 | "rgba(0,123,255,0.3)" 10 | ]; 11 | } 12 | const chart = new Chart(canvas, { 13 | type: "pie", 14 | data: { 15 | datasets: [ 16 | { 17 | hoverBorderColor: hoverBorderColor, 18 | data: data, 19 | backgroundColor: backgroundColor 20 | } 21 | ], 22 | labels: labels 23 | }, 24 | options: { 25 | legend: { position: "bottom", labels: { padding: 25, boxWidth: 20 } }, 26 | cutoutPercentage: 0, 27 | tooltips: { custom: !1, mode: "index", position: "nearest" } 28 | } 29 | }); 30 | 31 | return chart; 32 | } 33 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/datatables.helper.ts: -------------------------------------------------------------------------------- 1 | import { DataTableDirective } from 'angular-datatables'; 2 | import { Subject } from 'rxjs/internal/Subject'; 3 | 4 | export function refreshDataTable(dataTableElement: DataTableDirective, dataTableTrigger: Subject, forceClear?: boolean) { 5 | clearDataTable(dataTableElement, forceClear).then(() => { 6 | dataTableTrigger.next(); 7 | }); 8 | } 9 | 10 | export function clearDataTable(dataTableElement: DataTableDirective, force?: boolean) { 11 | return new Promise((resolve, reject) => { 12 | if (dataTableElement.dtInstance) { 13 | dataTableElement.dtInstance.then((dtInstance: DataTables.Api) => { 14 | if (force || dtInstance.data().any()) { 15 | dtInstance.clear().destroy(); 16 | } 17 | resolve(); 18 | }); 19 | } else { 20 | resolve(); 21 | } 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/functions.helper.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Stolen from: https://medium.com/@mhagemann/the-ultimate-way-to-slugify-a-url-string-in-javascript-b8e4a0d849e1 4 | */ 5 | export function slugify(str: string): string { 6 | const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;' 7 | const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------' 8 | const p = new RegExp(a.split('').join('|'), 'g') 9 | 10 | return str.toString().toLowerCase() 11 | .replace(/\s+/g, '-') // Replace spaces with - 12 | .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters 13 | .replace(/&/g, '-and-') // Replace & with 'and' 14 | .replace(/[^\u0600-\u06FF\w\-]+/g, '') // Remove all non-word characters ([\u0600-\u06FF] represent arabic letters) 15 | .replace(/\-\-+/g, '-') // Replace multiple - with single - 16 | .replace(/^-+/, '') // Trim - from start of text 17 | .replace(/-+$/, ''); // Trim - from end of text 18 | } 19 | 20 | export function now(): number { 21 | return !Date.now ? +new Date() : Date.now(); //new Date().getTime(); 22 | } 23 | 24 | /** 25 | * Stolen from: https://stackoverflow.com/a/13403498 26 | */ 27 | export function guid(): string { 28 | return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); 29 | } 30 | 31 | /** 32 | * Stolen from: https://stackoverflow.com/a/60461693 33 | */ 34 | export const isFile = (input: File|any) => 'File' in window && input instanceof File; 35 | 36 | /** 37 | * Stolen from: https://stackoverflow.com/a/24221895 38 | */ 39 | export function resolve(obj: object, ...path: string[]){ 40 | let current = obj; 41 | while(path.length) { 42 | if(typeof current !== 'object') return undefined; 43 | current = current[path.shift()]; 44 | } 45 | return current as any; 46 | } 47 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/layout.helper.ts: -------------------------------------------------------------------------------- 1 | //import * as $ from 'jquery'; // throw "Cannot call a namespace ('$')" error on build 2 | declare var $: any; 3 | import 'bootstrap'; 4 | 5 | $.extend($.easing, { 6 | easeOutSine: function(e, t, a, r, n) { 7 | return r * Math.sin((t / n) * (Math.PI / 2)) + a; 8 | } 9 | }); 10 | 11 | export function initLayout() { 12 | function t() { 13 | var e = $(".nav-wrapper"), t = e.height(); 14 | e[0] && e[0].scrollHeight > t ? e.css("overflowY", "auto") : e.css("overflowY", "none"); 15 | } 16 | $(window).resize(t); 17 | t(); 18 | } 19 | 20 | export function initDropdown() { 21 | ($(".dropdown-toggle") as any).dropdown(); 22 | var e = { duration: 270, easing: "easeOutSine" }; 23 | $(":not(.main-sidebar--icons-only) .dropdown").on( 24 | "show.bs.dropdown", 25 | function() { 26 | $(this) 27 | .find(".dropdown-menu") 28 | .first() 29 | .stop(!0, !0) 30 | .slideDown(e); 31 | } 32 | ); 33 | $(":not(.main-sidebar--icons-only) .dropdown").on( 34 | "hide.bs.dropdown", 35 | function() { 36 | $(this) 37 | .find(".dropdown-menu") 38 | .first() 39 | .stop(!0, !0) 40 | .slideUp(e); 41 | } 42 | ); 43 | } 44 | 45 | export function toggleSidebar() { 46 | if ($(".header-navbar").length) { 47 | ($(".header-navbar") as any).collapse("toggle"); 48 | } else { 49 | $(".main-sidebar").toggleClass("open"); 50 | } 51 | } 52 | 53 | export function initPopover(selector: string = '.popover') { 54 | /** 55 | * Stolen from: https://stackoverflow.com/a/19684440 56 | */ 57 | $(selector).popover({ 58 | trigger: 'manual', 59 | html: true, 60 | animation: false 61 | }).on('mouseenter', function () { 62 | var _this = this; 63 | $(this).popover('show'); 64 | $('.popover').on('mouseleave', function () { 65 | $(_this).popover('hide'); 66 | }); 67 | }).on('mouseleave', function () { 68 | var _this = this; 69 | setTimeout(function () { 70 | if (!$('.popover:hover').length) { 71 | $(_this).popover('hide'); 72 | } 73 | }, 300); 74 | }); 75 | } 76 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/posts.helper.ts: -------------------------------------------------------------------------------- 1 | declare var Quill: any; 2 | 3 | export function initTextEditor(selector: string, placeholder: string = '') { 4 | const quill = new Quill(selector, { 5 | modules: { 6 | toolbar: { 7 | container: [ 8 | [{ header: [1, 2, 3, 4, 5, !1] }], 9 | ["bold", "italic", "underline", "strike"], 10 | ["blockquote", "code-block"], 11 | //[{ header: 1 }, { header: 2 }], 12 | [{ list: "ordered" }, { list: "bullet" }], 13 | //[{ script: "sub" }, { script: "super" }], 14 | [{ color: [] }, { background: [] }], 15 | [{ align: [] }], 16 | [{ indent: "-1" }, { indent: "+1" }], 17 | ["link", "image", "video"], 18 | ["html"] 19 | ], 20 | handlers: { 21 | 'html': () => { } 22 | } 23 | } 24 | }, 25 | placeholder: placeholder, 26 | theme: "snow" 27 | }); 28 | 29 | /** 30 | * Stolen from: https://jsfiddle.net/nzolore/1jxy58vn/ 31 | */ 32 | const htmlButton = document.querySelector('.ql-html'); 33 | 34 | htmlButton.addEventListener('click', function() { 35 | let htmlEditor: any = document.querySelector('.ql-html-editor'); 36 | if (htmlEditor) { 37 | //console.log(htmlEditor.value.replace(/\n/g, "")); 38 | quill.root.innerHTML = htmlEditor.value.replace(/\n/g, ""); 39 | quill.container.removeChild(htmlEditor); 40 | } else { 41 | htmlEditor = document.createElement("textarea"); 42 | htmlEditor.className = 'ql-editor ql-html-editor' 43 | htmlEditor.innerHTML = quill.root.innerHTML; 44 | quill.container.appendChild(htmlEditor); 45 | } 46 | }); 47 | 48 | return quill; 49 | } 50 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/helpers/timestamp.helper.ts: -------------------------------------------------------------------------------- 1 | import { firestore } from 'firebase/app'; 2 | 3 | export function timestampToDate(timestamp: firestore.Timestamp): Date { 4 | if (timestamp instanceof firestore.Timestamp) { 5 | return new Date(+timestamp.seconds * 1000); 6 | } else { 7 | console.warn(`could not convert ${timestamp} to date!`); 8 | return timestamp; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/alert-type.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export type AlertType = 'primary' | 'secondary' | 'success' | 'warning' | 'danger'; 3 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/category.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Category { 3 | id?: string; 4 | label: string; 5 | slug: string; 6 | lang: string; 7 | createdAt?: number; 8 | updatedAt?: number; 9 | createdBy?: string; 10 | updatedBy?: string; 11 | } 12 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/document-translation.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface DocumentTranslation { 3 | [key: string]: string; // key == lang, value == document id 4 | } 5 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/menu.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Menu { 3 | id?: string; 4 | name: string; 5 | lang: string; 6 | items: MenuItem[]; 7 | } 8 | 9 | export interface MenuItem { 10 | title: string; 11 | url: string; 12 | //icon?: string; 13 | childrens: MenuItem[]; 14 | } 15 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/page.model.ts: -------------------------------------------------------------------------------- 1 | import { DocumentTranslation } from './document-translation'; 2 | import { Observable } from 'rxjs'; 3 | 4 | export interface Page { 5 | id?: string; 6 | title: string; 7 | slug: string; 8 | lang: string; 9 | blocks?: { [key: string]: PageBlock }; 10 | createdAt?: number; 11 | updatedAt?: number; 12 | createdBy?: string; 13 | author?: string|Observable; 14 | updatedBy?: string; 15 | translationId?: string; 16 | translations?: PageTranslation; // used to store translations on object fetch 17 | isTranslatable?: boolean; 18 | } 19 | 20 | export interface PageBlock { 21 | key?: string; 22 | name: string; 23 | type: PageBlockType; 24 | content: string; 25 | } 26 | 27 | export enum PageBlockType { 28 | Text = 'text', 29 | HTML = 'html', 30 | JSON = 'json' 31 | } 32 | 33 | export interface PageTranslation extends DocumentTranslation { } 34 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/post.model.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | import { DocumentTranslation } from './document-translation'; 3 | 4 | export interface Post { 5 | id?: string; 6 | lang: string; 7 | title: string; 8 | slug: string; 9 | date: number; // timestamp 10 | image?: File|string|Observable|{ path: string|any, url: string|Observable }; 11 | content: string; 12 | status: PostStatus; 13 | categories: string[]; 14 | createdAt?: number; 15 | updatedAt?: number; 16 | createdBy?: string; 17 | author?: string|Observable; 18 | updatedBy?: string; 19 | translationId?: string; 20 | translations?: PostTranslation; // used to store translations on object fetch 21 | isTranslatable?: boolean; 22 | } 23 | 24 | export enum PostStatus { 25 | Draft = 'draft', 26 | Published = 'published', 27 | Trash = 'trash' 28 | } 29 | 30 | export interface PostTranslation extends DocumentTranslation { } 31 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/translation.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Translation { 3 | id?: string; 4 | [key: string]: string; // key: value 5 | } 6 | 7 | export interface TranslationData { 8 | key: string; 9 | value: string; 10 | lang: string; 11 | } 12 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/collections/user.model.ts: -------------------------------------------------------------------------------- 1 | import { Observable } from 'rxjs'; 2 | 3 | export enum UserRole { 4 | Administrator = 'admin', 5 | Editor = 'editor', 6 | // Author = 'author', 7 | // Contributor = 'contributor', 8 | Guest = 'guest' 9 | } 10 | 11 | export interface User { 12 | id?: string; // document id == firebase user id 13 | firstName: string; 14 | lastName: string; 15 | email: string; 16 | password: string; 17 | birthDate: number; // timestamp 18 | role: UserRole; 19 | bio: string; 20 | avatar?: File|string|Observable|{ path: string|any, url: string|Observable }; 21 | createdAt?: number; 22 | updatedAt?: number; 23 | createdBy?: string; // creator id 24 | creator?: string|Observable; // used to fetch creator name without overriding createdBy field 25 | updatedBy?: string; 26 | } 27 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/language.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface Language { 3 | label: string; 4 | key: string; 5 | isActive: boolean; 6 | isRemovable: boolean; 7 | } 8 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/settings.model.ts: -------------------------------------------------------------------------------- 1 | import { Language } from './language.model'; 2 | 3 | export type SidebarStyle = 'expanded' | 'collapsed' | 'headerbar'; 4 | 5 | export interface Settings { 6 | language: string; 7 | sidebarStyle: SidebarStyle; 8 | supportedLanguages: Language[]; 9 | } 10 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/models/sidebar-item.model.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface SidebarItem { 3 | label: string; 4 | icon?: string; 5 | routerLink?: string | string[]; 6 | childrens?: SidebarItemChildren[]; 7 | isActive?: boolean; 8 | isHidden?: () => boolean 9 | } 10 | 11 | export interface SidebarItemChildren extends Omit { } 12 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/pipes/datetime.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | import { I18nService } from '../services/i18n.service'; 3 | import { DatePipe } from '@angular/common'; 4 | 5 | @Pipe({ 6 | name: 'datetime' 7 | }) 8 | export class DateTimePipe extends DatePipe implements PipeTransform { 9 | 10 | constructor(private i18nService: I18nService) { 11 | super(i18nService.getCurrentLanguage()); 12 | } 13 | 14 | transform(value: any, format?: string, timezone?: string, locale?: string): string { 15 | return super.transform(value, format || 'dd MMMM yyyy HH:mm', timezone, locale || this.i18nService.getCurrentLanguage()); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/pipes/escape-url.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | import { DomSanitizer } from '@angular/platform-browser'; 3 | 4 | @Pipe({ 5 | name: 'escapeUrl', 6 | pure: false 7 | }) 8 | export class EscapeUrlPipe implements PipeTransform { 9 | 10 | constructor(private sanitizer: DomSanitizer) { } 11 | 12 | transform(content: string|any) { 13 | return this.sanitizer.bypassSecurityTrustUrl(content); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/pipes/shortdate.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe } from '@angular/core'; 2 | import { DateTimePipe } from './datetime.pipe'; 3 | 4 | @Pipe({ 5 | name: 'shortdate' 6 | }) 7 | export class ShortDatePipe extends DateTimePipe { 8 | 9 | transform(value: any, format?: string, timezone?: string, locale?: string): string { 10 | return super.transform(value, format || 'dd MMMM yyyy', timezone, locale); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/pipes/timestamp.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe } from '@angular/core'; 2 | import { DateTimePipe } from './datetime.pipe'; 3 | import { timestampToDate } from '../helpers/timestamp.helper'; 4 | 5 | @Pipe({ 6 | name: 'timestamp' 7 | }) 8 | export class TimestampPipe extends DateTimePipe { 9 | 10 | transform(value: any, format?: string, timezone?: string, locale?: string): string { 11 | value = timestampToDate(value); 12 | return super.transform(value, format, timezone, locale); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/pipes/translate.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | import { I18nService } from '../services/i18n.service'; 3 | 4 | @Pipe({ 5 | name: 'translate' 6 | }) 7 | export class TranslatePipe implements PipeTransform { 8 | 9 | constructor(private i18nService: I18nService) { } 10 | 11 | transform(key: string, substitutions?: { [key: string]: string }): string { 12 | return this.i18nService.get(key, substitutions); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/alert.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { AlertType } from '../models/alert-type.model'; 3 | import { LocalStorageService } from './local-storage.service'; 4 | 5 | @Injectable() 6 | export class AlertService { 7 | 8 | message: string = null; 9 | type: AlertType = 'primary'; 10 | icon: string = null; 11 | isPersistent: boolean = false; 12 | private timeoutHandle: any = null; 13 | 14 | constructor(private localStorage: LocalStorageService) { 15 | const alert = this.localStorage.get('flash_alert'); 16 | if (alert) { 17 | this.set(alert.message, alert.type); 18 | this.localStorage.set('flash_alert', null); 19 | if (alert.timeout) { 20 | this.clearAfterTimeout(alert.timeout); 21 | } 22 | } 23 | } 24 | 25 | private set(message: string, type: AlertType, isFlashAlert: boolean = false, timeout: number = null, isPersistent: boolean = false) { 26 | if (isFlashAlert) { 27 | this.localStorage.set('flash_alert', { 28 | message: message, 29 | type: type, 30 | timeout: timeout 31 | }); 32 | } else { 33 | this.message = message; 34 | this.type = type; 35 | switch(this.type) { 36 | case 'primary': 37 | this.icon = 'info'; 38 | break; 39 | case 'success': 40 | this.icon = 'check'; 41 | break; 42 | case 'warning': 43 | this.icon = 'exclamation'; 44 | break; 45 | case 'danger': 46 | this.icon = 'ban'; 47 | break; 48 | default: 49 | this.icon = null; 50 | } 51 | if (timeout) { 52 | this.clearAfterTimeout(timeout); 53 | } 54 | this.isPersistent = isPersistent; 55 | } 56 | } 57 | 58 | private clearAfterTimeout(timeout: number) { 59 | if (this.timeoutHandle) { 60 | clearTimeout(this.timeoutHandle); 61 | } 62 | this.timeoutHandle = setTimeout(() => this.clear(), timeout); 63 | } 64 | 65 | clear(clearFlashAlert: boolean = false) { 66 | this.message = null; 67 | if (clearFlashAlert) { 68 | this.localStorage.set('flash_alert', null); 69 | } 70 | } 71 | 72 | info(message: string, isFlashAlert: boolean = false, timeout: number = null, isPersistent: boolean = false) { 73 | this.set(message, 'primary', isFlashAlert, timeout, isPersistent); 74 | } 75 | 76 | success(message: string, isFlashAlert: boolean = false, timeout: number = null, isPersistent: boolean = false) { 77 | this.set(message, 'success', isFlashAlert, timeout, isPersistent); 78 | } 79 | 80 | error(message: string, isFlashAlert: boolean = false, timeout: number = null, isPersistent: boolean = false) { 81 | this.set(message, 'danger', isFlashAlert, timeout, isPersistent); 82 | } 83 | 84 | warning(message: string, isFlashAlert: boolean = false, timeout: number = null, isPersistent: boolean = false) { 85 | this.set(message, 'warning', isFlashAlert, timeout, isPersistent); 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { AngularFireAuth } from '@angular/fire/auth'; 3 | import { first, map } from 'rxjs/operators'; 4 | import { auth } from 'firebase/app'; 5 | import { CurrentUserService } from './current-user.service'; 6 | 7 | @Injectable() 8 | export class AuthService { 9 | 10 | firebaseUser: firebase.User = null; 11 | lastError: firebase.FirebaseError = null; 12 | 13 | constructor(private afa: AngularFireAuth, private currentUser: CurrentUserService) { 14 | this.afa.auth.onAuthStateChanged((user: firebase.User) => { 15 | // console.log(user); 16 | this.firebaseUser = user; 17 | this.currentUser.set(user); 18 | }); 19 | } 20 | 21 | private setLastError(error: firebase.FirebaseError): void { 22 | this.lastError = error; 23 | console.error(`[${error.code}] ${error.message}`); 24 | } 25 | 26 | isSignedIn(): Promise { 27 | return this.afa.authState.pipe(first(), map((user: firebase.User) => !!user)).toPromise(); 28 | } 29 | 30 | signIn(email: string, password: string, isPersistent: boolean = false): Promise { 31 | // console.log('sign in', email, password); 32 | return new Promise((resolve, reject) => { 33 | if (!!this.firebaseUser) { 34 | console.log('already signed in!'); 35 | resolve(); 36 | } else { 37 | // Sign in 38 | const persistence = isPersistent ? auth.Auth.Persistence.LOCAL : auth.Auth.Persistence.SESSION; 39 | this.afa.auth.setPersistence(persistence).then(() => { 40 | this.afa.auth.signInWithEmailAndPassword(email, password).then(() => { 41 | resolve(); 42 | }).catch((error: firebase.FirebaseError) => { 43 | this.setLastError(error); 44 | reject(this.lastError); 45 | }); 46 | }).catch((error: firebase.FirebaseError) => { 47 | this.setLastError(error); 48 | reject(this.lastError); 49 | }); 50 | } 51 | }); 52 | } 53 | 54 | signOut(force: boolean = false): Promise { 55 | // console.log('sign out', this.firebaseUser); 56 | return new Promise((resolve, reject) => { 57 | if (force || !!this.firebaseUser) { 58 | this.afa.auth.signOut().then(() => { 59 | resolve(); 60 | }).catch((error: firebase.FirebaseError) => { 61 | this.setLastError(error); 62 | reject(this.lastError); 63 | }); 64 | } else { 65 | resolve(); 66 | } 67 | }); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/collections/abstract/document-translations.service.ts: -------------------------------------------------------------------------------- 1 | import { DatabaseService } from '../../database.service'; 2 | import { DocumentTranslation } from '../../../models/collections/document-translation'; 3 | 4 | export abstract class DocumentTranslationsService { 5 | 6 | constructor(protected db: DatabaseService, private collectionPath: string) { } 7 | 8 | protected addTranslation(lang: string, id: string, parentId?: string) { 9 | const translation = { [lang]: id }; 10 | return parentId ? this.db.setDocument(this.collectionPath, parentId, translation) : this.db.addDocument(this.collectionPath, translation); 11 | } 12 | 13 | protected getTranslations(id: string) { 14 | return this.db.getDocument(this.collectionPath, id); 15 | } 16 | 17 | protected getTranslationsWhere(field: string, operator: firebase.firestore.WhereFilterOp, value: string) { 18 | return this.db.getCollection(this.collectionPath, ref => ref.where(field, operator, value)); 19 | } 20 | 21 | protected deleteTranslation(id: string, lang?: string, translations?: DocumentTranslation) { 22 | const newTranslations = lang && translations ? Object.keys(translations).reduce((object, key) => { 23 | if (key !== lang) { 24 | object[key] = translations[key]; 25 | } 26 | return object; 27 | }, {}) : {}; 28 | return Object.keys(newTranslations).length > 0 ? this.db.setDocument(this.collectionPath, id, newTranslations, false) : this.db.deleteDocument(this.collectionPath, id); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/collections/categories.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { DatabaseService } from '../database.service'; 3 | import { Category } from '../../models/collections/category.model'; 4 | import { now } from '../../helpers/functions.helper'; 5 | import { map } from 'rxjs/operators'; 6 | 7 | @Injectable() 8 | export class CategoriesService { 9 | 10 | constructor(private db: DatabaseService) { } 11 | 12 | add(data: Category) { 13 | const category: Category = { 14 | label: data.label, 15 | slug: data.slug, 16 | lang: data.lang, 17 | createdAt: now(), // timestamp 18 | updatedAt: null, 19 | createdBy: this.db.currentUser.id, 20 | updatedBy: null 21 | }; 22 | return this.db.addDocument('categories', category); 23 | } 24 | 25 | get(id: string) { 26 | return this.db.getDocument('categories', id).pipe(map((category: Category) => { 27 | category.id = id; 28 | return category; 29 | })); 30 | } 31 | 32 | getAll() { 33 | return this.db.getCollection('categories'); 34 | } 35 | 36 | getWhere(field: string, operator: firebase.firestore.WhereFilterOp, value: string) { 37 | return this.db.getCollection('categories', ref => ref.where(field, operator, value)); 38 | } 39 | 40 | edit(id: string, data: Category) { 41 | const category: Category = { 42 | label: data.label, 43 | slug: data.slug, 44 | lang: data.lang, 45 | updatedAt: now(), 46 | updatedBy: this.db.currentUser.id 47 | }; 48 | return this.db.setDocument('categories', id, category); 49 | } 50 | 51 | delete(id: string) { 52 | return this.db.deleteDocument('categories', id); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/collections/config.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { DatabaseService } from '../database.service'; 3 | import { resolve } from '../../helpers/functions.helper'; 4 | 5 | @Injectable() 6 | export class ConfigService { 7 | 8 | // ToDo: Add/save the rest of settings in database & make them global for all users? 9 | 10 | constructor(private db: DatabaseService) { } 11 | 12 | getAll() { 13 | return this.db.getCollectionRef('config').get().toPromise(); 14 | } 15 | 16 | async get(documentPath: string, ...keys: string[]) { 17 | const doc = await this.db.getDocumentRef('config', documentPath).get().toPromise(); 18 | const data = doc.data(); 19 | return keys.length ? resolve(data, ...keys) : data; 20 | } 21 | 22 | set(documentPath: string, data: object) { 23 | return this.db.setDocument('config', documentPath, data); 24 | } 25 | 26 | async isRegistrationEnabled() { 27 | const enabled = await this.get('registration', 'enabled'); 28 | return enabled === false ? false : true; // don't mess with this line, since "enabled" value should be true when null or undefined 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/collections/translations.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { DatabaseService } from '../database.service'; 3 | import { Translation, TranslationData } from '../../models/collections/translation.model'; 4 | import { take, map } from 'rxjs/operators'; 5 | import { QueryFn, DocumentData } from '@angular/fire/firestore'; 6 | 7 | @Injectable() 8 | export class TranslationsService { 9 | 10 | constructor(private db: DatabaseService) { } 11 | 12 | add(data: TranslationData) { 13 | const translation: Translation = { [data.key]: data.value }; 14 | return this.db.setDocument('translations', data.lang, translation); 15 | } 16 | 17 | get(lang: string) { 18 | return this.db.getDocument('translations', lang); 19 | } 20 | 21 | getAll() { 22 | return this.db.getCollection('translations').pipe(map((translations: Translation[]) => { 23 | //console.log(translations); 24 | const allTranslations: TranslationData[] = []; 25 | translations.forEach((translation: Translation) => { 26 | //console.log(translation); 27 | const lang = translation.id; 28 | const keys = Object.keys(translation).filter((key: string) => key !== 'id'); 29 | keys.forEach((key: string) => { 30 | allTranslations.push({ 31 | key: key, 32 | value: translation[key], 33 | lang: lang 34 | }); 35 | }); 36 | }); 37 | return allTranslations; 38 | })); 39 | } 40 | 41 | getWhere(field: string, operator: firebase.firestore.WhereFilterOp, value: string) { 42 | return this.getWhereFn(ref => ref.where(field, operator, value)); 43 | } 44 | 45 | getWhereFn(queryFn: QueryFn) { 46 | return this.db.getCollection('translations', queryFn); 47 | } 48 | 49 | edit(data: TranslationData) { 50 | return this.add(data); 51 | } 52 | 53 | delete(key: string, lang: string) { 54 | return new Promise(async (resolve, reject) => { 55 | const translations: Translation = await this.get(lang).pipe(take(1)).toPromise(); 56 | if (translations[key]) { 57 | delete translations[key]; 58 | this.db.setDocument('translations', lang, translations, false).then(() => { 59 | resolve(); 60 | }).catch((error: Error) => { 61 | reject(error); 62 | }); 63 | } else { 64 | resolve(); 65 | } 66 | }); 67 | } 68 | 69 | keyExists(key: string, lang: string): Promise { 70 | return new Promise((resolve, reject) => { 71 | this.db.getDocumentRef('translations', lang).get().toPromise().then((doc) => { 72 | const translations = doc.data(); 73 | if (translations && translations[key]) { 74 | resolve(true); 75 | } else { 76 | resolve(false); 77 | } 78 | }).catch((error: Error) => { 79 | console.log(error); 80 | resolve(false); 81 | }); 82 | }); 83 | } 84 | 85 | // async countAll() { 86 | // const translations = await this.getAll().pipe(take(1)).toPromise(); 87 | // return translations ? translations.length : 0; 88 | // } 89 | 90 | // async countWhereFn(queryFn: QueryFn) { 91 | // const translations = await this.getWhereFn(queryFn).pipe(take(1)).toPromise(); 92 | // return translations ? translations.length : 0; 93 | // } 94 | 95 | // countWhere(field: string, operator: firebase.firestore.WhereFilterOp, value: string) { 96 | // return this.countWhereFn(ref => ref.where(field, operator, value)); 97 | // } 98 | 99 | private count(docs: DocumentData[]) { 100 | let count = 0; 101 | docs.forEach((doc: DocumentData) => { 102 | count += Object.keys(doc.data()).length; 103 | }); 104 | return count; 105 | } 106 | 107 | async countAll() { 108 | const docs = await this.db.getDocumentsDataAsPromise('translations'); 109 | return this.count(docs); 110 | } 111 | 112 | async countWhereFn(queryFn: QueryFn) { 113 | const docs = await this.db.getDocumentsDataAsPromise('translations', queryFn); 114 | return this.count(docs); 115 | } 116 | 117 | countWhere(field: string, operator: firebase.firestore.WhereFilterOp, value: string) { 118 | return this.countWhereFn(ref => ref.where(field, operator, value)); 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/current-user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { take, takeUntil } from 'rxjs/operators'; 3 | import { User, UserRole } from '../models/collections/user.model'; 4 | import { UsersService } from './collections/users.service'; 5 | import { DatabaseService } from './database.service'; 6 | import { Subject } from 'rxjs'; 7 | 8 | @Injectable() 9 | export class CurrentUserService { 10 | 11 | data: User = null; 12 | private dataChange: Subject = new Subject(); // emit User object on each user change 13 | private userChange: Subject = new Subject(); // used to stop users service subscription on each new subscription 14 | 15 | constructor(private usersService: UsersService, private db: DatabaseService) { 16 | this.db.setCurrentUser(this); // used to avoid circular dependency issue (when injecting currentUser service into users or database services) 17 | } 18 | 19 | get() { 20 | return this.data ? this.data : this.dataChange.pipe(take(1)).toPromise(); 21 | } 22 | 23 | set(user: firebase.User) { 24 | this.unsubscribe(); 25 | if (user) { 26 | this.usersService.get(user.uid).pipe( 27 | takeUntil(this.userChange) 28 | ).subscribe((user: User) => { 29 | if (user) { 30 | user.avatar = this.usersService.getAvatarUrl(user.avatar as string); 31 | } 32 | this.data = user; 33 | this.dataChange.next(this.data); 34 | }); 35 | } 36 | } 37 | 38 | unsubscribe() { 39 | this.userChange.next(); 40 | } 41 | 42 | private hasRole(role: UserRole) { 43 | return this.data && this.data.role === role; 44 | } 45 | 46 | isAdmin() { 47 | return this.hasRole(UserRole.Administrator); 48 | } 49 | 50 | isGuest() { 51 | return this.hasRole(UserRole.Guest); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/firebase-user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { auth, initializeApp } from 'firebase/app'; 3 | import { FireAdminService } from '../fire-admin.service'; 4 | import { User } from '../models/collections/user.model'; 5 | 6 | /** 7 | * This service is used to create/update users without signing out the current user 8 | * (otherwise, we'll need to use firebase functions or firebase-admin sdk) 9 | * 10 | * source idea: https://stackoverflow.com/a/38013551 11 | */ 12 | 13 | @Injectable() 14 | export class FirebaseUserService { 15 | 16 | private app: firebase.app.App; 17 | 18 | constructor(private fas: FireAdminService) { 19 | const config = FireAdminService.getFirebaseConfig(this.fas); 20 | // console.log(config); 21 | this.app = initializeApp(config, 'FirebaseUserApp'); 22 | } 23 | 24 | create(email: string, password: string): Promise { 25 | return new Promise((resolve, reject) => { 26 | this.app.auth().createUserWithEmailAndPassword(email, password).then((userCredential: auth.UserCredential) => { 27 | // console.log('User ' + userCredential.user.uid + ' created successfully!'); 28 | this.app.auth().signOut(); 29 | resolve(userCredential.user.uid); 30 | }).catch((error: firebase.FirebaseError) => { 31 | reject(error); 32 | }); 33 | }); 34 | } 35 | 36 | register(user: User): Promise { 37 | return new Promise((resolve, reject) => { 38 | this.app.auth().createUserWithEmailAndPassword(user.email, user.password).then((userCredential: auth.UserCredential) => { 39 | // console.log('User ' + userCredential.user.uid + ' created successfully!'); 40 | this.app.firestore().collection('users').doc(userCredential.user.uid).set(user).then(() => { 41 | this.app.firestore().collection('config').doc('registration').set({ enabled: false }, { merge: true }).then(() => { 42 | this.app.auth().signOut(); 43 | resolve(userCredential.user.uid); 44 | }).catch((error: firebase.FirebaseError) => { 45 | this.app.auth().signOut(); 46 | reject(error); 47 | }); 48 | }).catch((error: firebase.FirebaseError) => { 49 | this.app.auth().signOut(); 50 | reject(error); 51 | }); 52 | }).catch((error: firebase.FirebaseError) => { 53 | reject(error); 54 | }); 55 | }); 56 | } 57 | 58 | updateEmail(email: string, password: string, newEmail: string): Promise { 59 | return new Promise((resolve, reject) => { 60 | this.app.auth().signInWithEmailAndPassword(email, password).then(() => { 61 | this.app.auth().currentUser.updateEmail(newEmail).then(() => { 62 | resolve(); 63 | }).catch((error: firebase.FirebaseError) => { 64 | reject(error); 65 | }).finally(() => { 66 | this.app.auth().signOut(); 67 | }); 68 | }).catch((error: firebase.FirebaseError) => { 69 | reject(error); 70 | }); 71 | }); 72 | } 73 | 74 | updatePassword(email: string, password: string, newPassword: string): Promise { 75 | return new Promise((resolve, reject) => { 76 | this.app.auth().signInWithEmailAndPassword(email, password).then(() => { 77 | this.app.auth().currentUser.updatePassword(newPassword).then(() => { 78 | resolve(); 79 | }).catch((error: firebase.FirebaseError) => { 80 | reject(error); 81 | }).finally(() => { 82 | this.app.auth().signOut(); 83 | }); 84 | }).catch((error: firebase.FirebaseError) => { 85 | reject(error); 86 | }); 87 | }); 88 | } 89 | 90 | delete(email: string, password: string): Promise { 91 | return new Promise((resolve, reject) => { 92 | this.app.auth().signInWithEmailAndPassword(email, password).then(() => { 93 | this.app.auth().currentUser.delete().then(() => { 94 | resolve(); 95 | }).catch((error: firebase.FirebaseError) => { 96 | reject(error); 97 | }).finally(() => { 98 | this.app.auth().signOut(); 99 | }); 100 | }).catch((error: firebase.FirebaseError) => { 101 | reject(error); 102 | }); 103 | }); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/i18n.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { SettingsService } from './settings.service'; 3 | import { en } from '../i18n/en'; 4 | import { fr } from '../i18n/fr'; 5 | 6 | @Injectable() 7 | export class I18nService { 8 | 9 | private lang: string = 'en'; 10 | private translations: object = { 11 | 'en': en, 12 | 'fr': fr 13 | }; 14 | 15 | constructor(private settings: SettingsService) { 16 | // Set language 17 | if (this.settings.language) { 18 | this.setLanguage(this.settings.language); 19 | } 20 | } 21 | 22 | setLanguage(lang: string): void { 23 | this.lang = lang; 24 | } 25 | 26 | getCurrentLanguage(): string { 27 | return this.lang; 28 | } 29 | 30 | get(key: string, substitutions?: { [key: string]: string }): string { 31 | return this.translations[this.lang][key] ? this.replace(this.translations[this.lang][key], substitutions) : key; 32 | } 33 | 34 | private replace(translation: string, substitutions?: { [key: string]: string }): string { 35 | let result = translation; 36 | if (substitutions) { 37 | Object.keys(substitutions).forEach((key: string) => { 38 | result = result.replace(new RegExp(`\\$\\{${key}\\}`, 'gi'), substitutions[key]); 39 | }); 40 | } 41 | // console.log('translation:', result); 42 | return result; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/local-storage.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | 3 | @Injectable() 4 | export class LocalStorageService { 5 | 6 | constructor() { } 7 | 8 | get(key: string): any { 9 | const value = localStorage.getItem(key); 10 | let finalValue; 11 | try { 12 | finalValue = JSON.parse(value); 13 | } 14 | catch(error) { 15 | finalValue = value; 16 | } 17 | return finalValue; 18 | } 19 | 20 | set(key: string, value: any): void { 21 | let finalValue; 22 | try { 23 | finalValue = JSON.stringify(value); 24 | } 25 | catch(error) { 26 | finalValue = value; 27 | } 28 | localStorage.setItem(key, finalValue); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/navigation.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { Router } from '@angular/router'; 3 | 4 | @Injectable() 5 | export class NavigationService { 6 | 7 | private rootPath: string = null; 8 | 9 | constructor(public router: Router) { 10 | //console.log(this.router.config[0].path); 11 | this.rootPath = this.router.config[0].path; 12 | } 13 | 14 | private getQueryParams(path: string): Object { 15 | const queryParams = path.split('?')[1] || ''; 16 | const params = queryParams.length ? queryParams.split('&') : []; 17 | let pair = null; 18 | let data = {}; 19 | params.forEach((d) => { 20 | pair = d.split('='); 21 | data[`${pair[0]}`] = pair[1]; 22 | }); 23 | return data; 24 | } 25 | 26 | redirectTo(...path: string[]): void { 27 | //console.log(path, this.getQueryParams(path[0])); 28 | this.router.navigate(this.getRouterLink(...path), { queryParams: this.getQueryParams(path[0]) }); 29 | } 30 | 31 | getRouterLink(...path: string[]): string[] { 32 | const root: any = this.rootPath ? '/' + this.rootPath : []; 33 | path = path.map((segment: string) => segment.split('?')[0]); // clean up / remove query params 34 | return [root, ...path]; 35 | } 36 | 37 | setRootPath(path: string): void { 38 | this.rootPath = path; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/settings.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from "@angular/core"; 2 | import { LocalStorageService } from './local-storage.service'; 3 | import { Settings, SidebarStyle } from '../models/settings.model'; 4 | import { Language } from '../models/language.model'; 5 | 6 | @Injectable() 7 | export class SettingsService implements Settings { 8 | 9 | language: string; 10 | sidebarStyle: SidebarStyle; 11 | supportedLanguages: Language[]; 12 | 13 | constructor(private localStorage: LocalStorageService) { 14 | const settings = this.localStorage.get('settings'); 15 | const defaults = this.getDefaults(); 16 | this.set({...defaults, ...settings}); // any existing settings value will override defaults 17 | } 18 | 19 | private getDefaults(): Settings { 20 | return { 21 | language: 'en', 22 | sidebarStyle: 'expanded', 23 | supportedLanguages: [ 24 | { 25 | label: 'English', 26 | key: 'en', 27 | isActive: true, 28 | isRemovable: false 29 | }, 30 | { 31 | label: 'French', 32 | key: 'fr', 33 | isActive: true, 34 | isRemovable: false 35 | }, 36 | { 37 | label: 'Arabic', 38 | key: 'ar', 39 | isActive: true, 40 | isRemovable: false 41 | } 42 | ] 43 | }; 44 | } 45 | 46 | private set(settings: Settings) { 47 | this.language = settings.language; 48 | this.sidebarStyle = settings.sidebarStyle; 49 | this.supportedLanguages = settings.supportedLanguages; 50 | } 51 | 52 | save() { 53 | this.localStorage.set('settings', { 54 | language: this.language, 55 | sidebarStyle: this.sidebarStyle, 56 | supportedLanguages: this.supportedLanguages 57 | }); 58 | } 59 | 60 | reset() { 61 | const defaults = this.getDefaults(); 62 | this.set(defaults); 63 | } 64 | 65 | supportedLanguageExists(label: string, key: string) { 66 | return this.supportedLanguages.find((lang: Language) => lang.label.toLocaleLowerCase() == label.toLocaleLowerCase()) || this.supportedLanguages.find((lang: Language) => lang.key.toLocaleLowerCase() == key.toLocaleLowerCase()); 67 | } 68 | 69 | getActiveSupportedLanguages() { 70 | return this.supportedLanguages.filter((lang: Language) => lang.isActive); 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /projects/fire-admin/src/lib/services/storage.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { AngularFireStorage, AngularFireUploadTask } from '@angular/fire/storage'; 3 | 4 | @Injectable() 5 | export class StorageService { 6 | 7 | constructor(private storage: AngularFireStorage) { } 8 | 9 | get(path: string) { 10 | return this.storage.ref(path); 11 | } 12 | 13 | upload(path: string, file: File): AngularFireUploadTask { 14 | return this.get(path).put(file); 15 | } 16 | 17 | delete(path: string) { 18 | return this.get(path).delete(); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /projects/fire-admin/src/public-api.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Public API Surface of fire-admin 3 | */ 4 | 5 | export * from './lib/fire-admin.service'; 6 | export * from './lib/fire-admin.component'; 7 | export * from './lib/fire-admin.module'; 8 | -------------------------------------------------------------------------------- /projects/fire-admin/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone'; 4 | import 'zone.js/dist/zone-testing'; 5 | import { getTestBed } from '@angular/core/testing'; 6 | import { 7 | BrowserDynamicTestingModule, 8 | platformBrowserDynamicTesting 9 | } from '@angular/platform-browser-dynamic/testing'; 10 | 11 | declare const require: any; 12 | 13 | // First, initialize the Angular testing environment. 14 | getTestBed().initTestEnvironment( 15 | BrowserDynamicTestingModule, 16 | platformBrowserDynamicTesting() 17 | ); 18 | // Then we find all the tests. 19 | const context = require.context('./', true, /\.spec\.ts$/); 20 | // And load the modules. 21 | context.keys().map(context); 22 | -------------------------------------------------------------------------------- /projects/fire-admin/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/lib", 5 | "target": "es2015", 6 | "declaration": true, 7 | "inlineSources": true, 8 | "types": [], 9 | "lib": [ 10 | "dom", 11 | "es2018" 12 | ] 13 | }, 14 | "angularCompilerOptions": { 15 | "annotateForClosureCompiler": true, 16 | "skipTemplateCodegen": true, 17 | "strictMetadataEmit": true, 18 | "fullTemplateTypeCheck": true, 19 | "strictInjectionParameters": true, 20 | "enableResourceInlining": true 21 | }, 22 | "exclude": [ 23 | "src/test.ts", 24 | "**/*.spec.ts" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /projects/fire-admin/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts" 12 | ], 13 | "include": [ 14 | "**/*.spec.ts", 15 | "**/*.d.ts" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /projects/fire-admin/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "lib", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "lib", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /screenshots/dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/screenshots/dashboard.png -------------------------------------------------------------------------------- /screenshots/user-profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FirebaseGoodies/FireAdmin/8471f1969ed892384d61736f371c9792766939c9/screenshots/user-profile.png -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ], 21 | "paths": { 22 | "fire-admin": [ 23 | "dist/fire-admin" 24 | ], 25 | "fire-admin/*": [ 26 | "dist/fire-admin/*" 27 | ] 28 | } 29 | }, 30 | "angularCompilerOptions": { 31 | "fullTemplateTypeCheck": true, 32 | "strictInjectionParameters": true 33 | } 34 | } -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "array-type": false, 8 | "arrow-parens": false, 9 | "deprecation": { 10 | "severity": "warning" 11 | }, 12 | "import-blacklist": [ 13 | true, 14 | "rxjs/Rx" 15 | ], 16 | "interface-name": false, 17 | "max-classes-per-file": false, 18 | "max-line-length": [ 19 | true, 20 | 140 21 | ], 22 | "member-access": false, 23 | "member-ordering": [ 24 | true, 25 | { 26 | "order": [ 27 | "static-field", 28 | "instance-field", 29 | "static-method", 30 | "instance-method" 31 | ] 32 | } 33 | ], 34 | "no-consecutive-blank-lines": false, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-empty": false, 44 | "no-inferrable-types": [ 45 | true, 46 | "ignore-params" 47 | ], 48 | "no-non-null-assertion": true, 49 | "no-redundant-jsdoc": true, 50 | "no-switch-case-fall-through": true, 51 | "no-var-requires": false, 52 | "object-literal-key-quotes": [ 53 | true, 54 | "as-needed" 55 | ], 56 | "object-literal-sort-keys": false, 57 | "ordered-imports": false, 58 | "quotemark": [ 59 | true, 60 | "single" 61 | ], 62 | "trailing-comma": false, 63 | "component-class-suffix": true, 64 | "contextual-lifecycle": true, 65 | "directive-class-suffix": true, 66 | "no-conflicting-lifecycle": true, 67 | "no-host-metadata-property": true, 68 | "no-input-rename": true, 69 | "no-inputs-metadata-property": true, 70 | "no-output-native": true, 71 | "no-output-on-prefix": true, 72 | "no-output-rename": true, 73 | "no-outputs-metadata-property": true, 74 | "template-banana-in-box": true, 75 | "template-no-negated-async": true, 76 | "use-lifecycle-interface": true, 77 | "use-pipe-transform-interface": true 78 | } 79 | } 80 | --------------------------------------------------------------------------------