Merge pull request #491 from eclipse/CHE-567

CHE-567: add directive for formating output
6.19.x
Anna Shumilova 2016-02-27 14:04:18 +02:00
commit fd8f0225c5
6 changed files with 115 additions and 1 deletions

View File

@ -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))

View File

@ -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%));
}
}

View File

@ -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"
}
]

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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, '<br/>')
this.outputColors.forEach((outputColor) => {
regExp = new RegExp('\\[\\s*' + outputColor.type + '\\s*\\]', 'g');
result = result.replace(regExp, '[<span style=\"color: ' + outputColor.color + '\">' + outputColor.type + '</span>]')
});
result = '<span>' + result + '</span>';
element.html(this.$compile(result)($scope));
});
}
}