Commit b8940504 authored by Floyd Hightower's avatar Floyd Hightower

Initial commit of basic framework

parents
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "Playbook-Multimeter"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "",
"styles": [
"styles.less"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "less",
"component": {}
}
}
[bumpversion]
current_version = 0.1.0
commit = True
tag = True
[bumpversion:file:./install.json]
search = "programVersion": "{current_version}"
replace = "programVersion": "{new_version}"
[bumpversion:file:./Gruntfile.js]
search = version: '{current_version}'
replace = version: '{new_version}'
[bumpversion:file:./package.json]
search = "version": "{current_version}",
replace = "version": "{new_version}",
# Editor configuration, see http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
max_line_length = off
trim_trailing_whitespace = false
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/dist-server
/tmp
/out-tsc
# dependencies
/node_modules
# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
# misc
/.sass-cache
/connect.lock
/coverage
/libpeerconnection.log
npm-debug.log
yarn-error.log
testem.log
/typings
# e2e
/e2e/*.js
/e2e/*.map
# System Files
.DS_Store
Thumbs.db
target/
# Node generated files
node_modules
npm-debug.log
# OS generated files
Thumbs.db
.DS_Store
# Ignored files
*.ts
!*.d.ts
var grunt = require('grunt');
var path = require('path');
var mkdirp = require('mkdirp');
grunt.initConfig({
app: {
name: 'TCS_-_Playbook_Multimeter',
version: '0.1.0'
},
copy: {
main: {
cwd: 'target/dist/',
src: ['**', '!*.eot', '!*.svg', '!*.ttf', '!*.woff'],
dest: 'target/<%= app.name %>_v<%= app.version %>/ui/',
expand: true
},
installJson: {
src: 'install.json',
dest: 'target/<%= app.name %>_v<%= app.version %>',
expand: true
},
readme: {
src: 'README.md',
dest: 'target/<%= app.name %>_v<%= app.version %>',
expand: true
},
parameters: {
src: 'install.json',
dest: 'target/<%= app.name %>_v<%= app.version %>/ui',
expand: true
}
},
clean: {
bundle: {
src: [
'target/'
],
options: {
expand: true
}
}
},
exec: {
createDirectory: {
cmd: function() {
var dir = 'target/dist';
mkdirp(dir, console.log);
return 'ls';
}
},
buildProd: path.relative('', 'node_modules/.bin/ng build') + ' --aot --prod --output-path target/dist --base-href .',
buildDev: path.relative('', 'node_modules/.bin/ng build') + ' --aot --output-path target/dist --base-href .',
serve: path.relative('', 'node_modules/.bin/ng serve')
},
tslint: {
options: {
configuration: grunt.file.readJSON('tslint.json')
},
files: {
src: ['app/**/*.ts']
}
},
compress: {
main: {
options: {
archive: 'target/<%= app.name %>_v<%= app.version %>.tcx',
pretty: true,
mode: 'zip'
},
expand: true,
cwd: 'target/<%= app.name %>_v<%= app.version %>/',
src: ['**/*'],
dest: '/<%= app.name %>_v<%= app.version %>/'
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-exec');
grunt.registerTask(
'buildProd',
'Compiles all assets and source files into build directory.',
[
'clean',
'exec:createDirectory',
'exec:buildProd',
'copy',
'compress',
]
);
grunt.registerTask(
'buildDev',
'Compiles all assets and source files into build directory.',
[
'clean',
'exec:createDirectory',
'exec:buildDev',
'copy',
'compress'
]
);
grunt.registerTask(
'serve',
'Runs the build, then serves the project locally.',
[
'exec:serve'
]
);
grunt.registerTask(
'default',
'Run default build',
[
'buildProd'
]
);
.DEFAULT_GOAL := help
define PRINT_HELP_PYSCRIPT
import re, sys
for line in sys.stdin:
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
if match:
target, help = match.groups()
print("%-20s %s" % (target, help))
endef
export PRINT_HELP_PYSCRIPT
help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
setup: ## prepare app for local testing or deployment
npm install
pack: ## package the app for PRODUCTION
grunt buildProd
packDev: ## package the app for DEVELOPMENT
grunt buildDev
run: ## run the app locally
ng serve -o
# Playbook Multimeter
Spaces app and playbook component to manage tests and view data across multiple playbooks.
## Getting Started
1. Setup your environment for testing:
```
make setup
```
2. Run the app to get started:
```
make run
```
This is using the [ng serve](https://github.com/angular/angular-cli/wiki/serve) command to run the app. You can leave this running and it will refresh to serve the most up to date version of the app as you make changes. Let's leave it running an open a new tab in your command line.
3. Let's get familiar with the app by removing the pop-up that says "This is the start of something great!":
- Open `src/app/main.component.ts`
- Remove the line that says:
```typescript
this.messages.showSuccess('Success Message', 'This is the start of something great!');
```
Now check the app and you will see that the pop-up is no longer shown. The `main.component.ts` file can be considered the quarter-back for the app. The routes are defined in `src/app/app-routing.module.ts` and you can change a route by calling the `goTo` function in `main.component.ts`.
4. To add a new [component](https://angular.io/guide/architecture-components) to the app, run:
```
cd src/app/
mkdir components # only have to do this the first time you create a component
cd components
ng generate component <COMPONENT_NAME>
```
## Build App For Release
```
make pack
```
This will package the app as `target/TCS_-_Playbook_Multimeter.tcx`.
## Build App in Development Mode (does not minify or uglify code, so it can be debugged in browser)
```
make pack-dev
```
## Deploy
In the ThreatConnect UI install the App (the `.tcx` file) created in the [Build App for Release](#build-app-for-release) section.
## Credits
This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and [Floyd Hightower's Spaces App Template](https://github.com/fhightower-templates/threatconnect-angular-spaces-template).
import { AppPage } from './app.po';
describe('context-udpate App', () => {
let page: AppPage;
beforeEach(() => {
page = new AppPage();
});
it('should display welcome message', () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('Welcome to app!');
});
});
import { browser, by, element } from 'protractor';
export class AppPage {
navigateTo() {
return browser.get('/');
}
getParagraphText() {
return element(by.css('app-root h1')).getText();
}
}
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/e2e",
"baseUrl": "./",
"module": "commonjs",
"target": "es5",
"types": [
"jasmine",
"jasminewd2",
"node"
]
}
}
{
"allowOnDemand": true,
"languageVersion": "7",
"params": [{
"encrypt": false,
"label": "Api User",
"name": "api_user",
"sequence": 1,
"type": "String",
"validValues": ["${USER:TEXT}", "${ORGANIZATION:TEXT}"]
}, {
"encrypt": true,
"label": "API Token",
"name": "api_token",
"sequence": 2,
"type": "String",
"validValues": ["${USER:KEYCHAIN}", "${ORGANIZATION:KEYCHAIN}"]
}, {
"default": "info",
"encrypt": false,
"label": "Logging Level",
"name": "logging",
"sequence": 3,
"type": "Choice",
"validValues": [
"debug",
"info",
"warn",
"error",
"critical"
]
}],
"programLanguage": "NONE",
"programVersion": "0.1.0",
"runtimeContext": [],
"runtimeLevel": "SpaceOrganization"
}
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
This diff is collapsed.
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
const { SpecReporter } = require('jasmine-spec-reporter');
exports.config = {
allScriptsTimeout: 11000,
specs: [
'./e2e/**/*.e2e-spec.ts'
],
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
baseUrl: 'http://localhost:4200/',
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {}
},
onPrepare() {
require('ts-node').register({
project: 'e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
}
};
import { NgModule } from '@angular/core';
import {
RouterModule,
Routes
}
from '@angular/router';
import { MainComponent } from './main.component';
import { SpacesBaseService } from 'spaces-ng';
const routes: Routes = [{
path: '',
component: MainComponent,
resolve: {base: SpacesBaseService},
}, {
path: 'index.html',
component: MainComponent,
resolve: {base: SpacesBaseService},
}];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
<div class="spaces-content">
<p-growl [value]="msgs"></p-growl>
<router-outlet></router-outlet>
</div>
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
}));
});
import {
Component,
} from '@angular/core';
import {
Router
} from '@angular/router';
import {
SpacesBaseService,
SpacesLoggingService,
SpacesMessagesService,
SpacesStorageService
} from 'spaces-ng/';
import {Message} from 'primeng/api';
@Component({
templateUrl: './app.component.html',
selector: 'tc-app'
})
export class AppComponent {
constructor(
private logging: SpacesLoggingService,
private messages: SpacesMessagesService,
private router: Router,
private spacesBase: SpacesBaseService,
private storage: SpacesStorageService
) {
this.logging.logLevel = 'debug'; // set app default logging level
this.logging.moduleColor('#633974', '#fff', 'AppComponent'); // set logging console colors
}
get msgs(): Message[] {
return this.messages.msgs;
}
}
/* Core */
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
/* Routing */
import { AppRoutingModule } from './app-routing.module';
/* Third-Party */
import {
BowserModule,
BowserService
} from 'ngx-bowser';
import {
AccordionModule,
ButtonModule,
DataTableModule,
DialogModule,
DropdownModule,
GrowlModule,
InputTextModule,
PanelModule,
SharedModule,
StepsModule,
TabViewModule
} from 'primeng/primeng';
import { TableModule } from 'primeng/table';
/* Components */
import { AppComponent } from './app.component'