From 04de24b206f9451645d62c78a71e01f63ad1be06 Mon Sep 17 00:00:00 2001 From: Ann Shumilova Date: Wed, 24 Feb 2016 15:00:34 +0200 Subject: [PATCH] CHE-567: add directive for formating output Signed-off-by: Ann Shumilova --- dashboard/gulp/build.js | 15 +++++- .../che-output-colors.constant.js.template | 19 +++++++ .../src/app/colors/che-output-colors.json | 26 ++++++++++ dashboard/src/app/index.module.js | 2 + .../components/attribute/attribute-config.js | 3 ++ .../che-format-output.directive.js | 51 +++++++++++++++++++ 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 dashboard/src/app/colors/che-output-colors.constant.js.template create mode 100644 dashboard/src/app/colors/che-output-colors.json create mode 100644 dashboard/src/components/attribute/format-output/che-format-output.directive.js diff --git a/dashboard/gulp/build.js b/dashboard/gulp/build.js index 6e5a030417..5d40ec23f3 100644 --- a/dashboard/gulp/build.js +++ b/dashboard/gulp/build.js @@ -110,7 +110,7 @@ gulp.task('existingfonts', function () { .pipe(gulp.dest(conf.paths.dist + '/fonts/')); }); -gulp.task('fonts', ['colors', 'proxySettings', 'existingfonts'], function () { +gulp.task('fonts', ['colors', 'outputcolors', 'proxySettings', 'existingfonts'], function () { return gulp.src($.mainBowerFiles().concat('bower_components/material-design-iconfont/iconfont/*')) .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) .pipe($.flatten()) @@ -131,6 +131,19 @@ gulp.task('colors', ['colorstemplate'], function () { .pipe(gulp.dest("src/app/colors")); }); +gulp.task('outputcolorstemplate', function () { + return gulp.src('src/app/colors/che-output-colors.constant.js.template') + .pipe($.replace('%CONTENT%', fs.readFileSync('src/app/colors/che-output-colors.json'))) + .pipe($.replace('\"', '\'')) + .pipe(gulp.dest('src/app/colors/template')); +}); + +gulp.task('outputcolors', ['outputcolorstemplate'], function () { + return gulp.src("src/app/colors/template/che-output-colors.constant.js.template") + .pipe($.rename("che-output-colors.constant.js")) + .pipe(gulp.dest("src/app/colors")); +}); + gulp.task('proxySettingsTemplate', function () { return gulp.src("src/app/proxy/proxy-settings.constant.js.template") .pipe($.replace('%CONTENT%', options.server)) diff --git a/dashboard/src/app/colors/che-output-colors.constant.js.template b/dashboard/src/app/colors/che-output-colors.constant.js.template new file mode 100644 index 0000000000..65df546b6a --- /dev/null +++ b/dashboard/src/app/colors/che-output-colors.constant.js.template @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2015-2016 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + */ +'use strict'; + +export class CheOutputColorsConfig { + + constructor(register) { + // Register this factory + register.app.constant('jsonOutputColors', JSON.stringify(%CONTENT%)); + } +} diff --git a/dashboard/src/app/colors/che-output-colors.json b/dashboard/src/app/colors/che-output-colors.json new file mode 100644 index 0000000000..98be441967 --- /dev/null +++ b/dashboard/src/app/colors/che-output-colors.json @@ -0,0 +1,26 @@ +[ + { + "type": "DOCKER", + "color": "#4EABFF" + }, + { + "type": "INFO", + "color": "#FFFFFF" + }, + { + "type": "ERROR", + "color": "#FF2727" + }, + { + "type": "WARNING", + "color": "#F5A623" + }, + { + "type": "STDOUT", + "color": "#8ED72B" + }, + { + "type": "STDERR", + "color": "#FF4343" + } +] diff --git a/dashboard/src/app/index.module.js b/dashboard/src/app/index.module.js index 9770112e96..a3b62f55be 100644 --- a/dashboard/src/app/index.module.js +++ b/dashboard/src/app/index.module.js @@ -16,6 +16,7 @@ import {ComponentsConfig} from '../components/components-config'; import {AdminsConfig} from './admin/admin-config'; import {CheColorsConfig} from './colors/che-color.constant'; +import {CheOutputColorsConfig} from './colors/che-output-colors.constant'; import {CheCountriesConfig} from './countries/che-countries.constant'; import {DashboardConfig} from './dashboard/dashboard-config'; // switch to a config @@ -354,6 +355,7 @@ var instanceRegister = new Register(initModule); new ProxySettingsConfig(instanceRegister); new CheColorsConfig(instanceRegister); +new CheOutputColorsConfig(instanceRegister); new CheCountriesConfig(instanceRegister); new ComponentsConfig(instanceRegister); new AdminsConfig(instanceRegister); diff --git a/dashboard/src/components/attribute/attribute-config.js b/dashboard/src/components/attribute/attribute-config.js index e5883fabc4..d25d4d62ad 100644 --- a/dashboard/src/components/attribute/attribute-config.js +++ b/dashboard/src/components/attribute/attribute-config.js @@ -14,6 +14,7 @@ import {CheFocusable} from './focusable/che-focusable.directive'; import {CheAutoScroll} from './scroll/che-automatic-scroll.directive'; import {CheListOnScrollBottom} from './scroll/che-list-on-scroll-bottom.directive'; import {CheReloadHref} from './reload-href/che-reload-href.directive'; +import {CheFormatOutput} from './format-output/che-format-output.directive'; export class AttributeConfig { @@ -28,5 +29,7 @@ export class AttributeConfig { register.directive('cheReloadHref', CheReloadHref); + register.directive('cheFormatOutput', CheFormatOutput); + } } diff --git a/dashboard/src/components/attribute/format-output/che-format-output.directive.js b/dashboard/src/components/attribute/format-output/che-format-output.directive.js new file mode 100644 index 0000000000..6650917c48 --- /dev/null +++ b/dashboard/src/components/attribute/format-output/che-format-output.directive.js @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015-2016 Codenvy, S.A. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Codenvy, S.A. - initial API and implementation + */ +'use strict'; + +/** + * Defines a directive for formatting output. + * @author Ann Shumilova + */ +export class CheFormatOutput { + + /** + * Default constructor that is using resource + * @ngInject for Dependency injection + */ + constructor(jsonOutputColors, $compile) { + this.restrict = 'A'; + this.outputColors = angular.fromJson(jsonOutputColors); + this.$compile = $compile; + } + + /** + * Keep reference to the model controller + */ + link($scope, element, attr) { + $scope.$watch(attr.ngModel, (value) => { + if (!value || value.length === 0) { + return; + } + + var regExp = new RegExp('\n', 'g'); + var result = value.replace(regExp, '
') + + this.outputColors.forEach((outputColor) => { + regExp = new RegExp('\\[\\s*' + outputColor.type + '\\s*\\]', 'g'); + result = result.replace(regExp, '[' + outputColor.type + ']') + }); + + result = '' + result + ''; + element.html(this.$compile(result)($scope)); + }); + } +} +