Merge pull request #1805 from biblesyme/aaron-master

Polish code
This commit is contained in:
Vincent Fiduccia 2018-04-09 16:22:25 -07:00 committed by GitHub
commit 7a147fb56e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 157 additions and 107 deletions

View File

@ -98,13 +98,7 @@ var Pod = Resource.extend(DisplayImage, {
return resource;
}
}),
image: function () {
let containers = this.get('containers');
if(!containers.length){
return
}
return containers[0].image;
}.property('containers'),
isOn: function() {
return ['running','migrating','restarting'].indexOf(get(this,'state')) >= 0;
}.property('state'),

View File

@ -243,12 +243,16 @@ var Workload = Resource.extend(DisplayImage, StateCounts, EndpointPorts, {
}.property('canScale','scaleMin','scaleIncrement','scale'),
displayScale: function() {
let lcType = get(this, 'lcType');
if (lcType){
return get(this, 'intl').t('servicePage.multistat.daemonSetScale');
}
if ( get(this, 'isGlobalScale') ) {
return get(this, 'intl').t('servicePage.globalScale', {scale: get(this, 'scale')});
} else {
return get(this, 'scale');
}
}.property('scale','isGlobalScale'),
}.property('scale','isGlobalScale', 'lcType'),
canHaveSidekicks: true,
@ -259,7 +263,8 @@ var Workload = Resource.extend(DisplayImage, StateCounts, EndpointPorts, {
canUpgrade: true,
canHaveLabels: true,
canScale: computed('lcType', function() {
return get(this,'lcType') !== 'cronjob';
let lcType = get(this, 'lcType');
return lcType !== 'cronjob' && lcType !== 'daemonset';
}),
realButNotLb: true,
canHaveLinks: true,

View File

@ -47,22 +47,16 @@
</div>
<div class="row banner bg-info basics mt-0" style="border-top: none;">
{{#if service.canScale}}
<div class="vertical-middle">
<label class="acc-label vertical-middle p-0">{{t 'servicePage.multistat.scale'}}</label>
{{#if (eq service.type 'daemonSet')}}
{{t "servicePage.multistat.daemonSetScale"}}
{{else}}
<span class="pr-5">
{{service.displayScale}}
</span>
<div class="btn-group btn-group-xs p-0">
<button class="btn btn-xs bg-primary" {{action "scaleDown" target=service}} disabled={{not service.canScaleDown}}><i class="icon icon-minus icon-fw"/></button>
<button style="margin-left: -1px;" class="btn btn-xs bg-primary" {{action "scaleUp" target=service}} disabled={{not service.canScaleUp}}><i class="icon icon-plus icon-fw"/></button>
</div>
{{/if}}
<div class="vertical-middle">
<label class="acc-label vertical-middle p-0">{{t 'servicePage.multistat.scale'}}</label>
<span class="pr-5">
{{service.displayScale}}
</span>
<div class="btn-group btn-group-xs p-0">
<button class="btn btn-xs bg-primary" {{action "scaleDown" target=service}} disabled={{not service.canScaleDown}}><i class="icon icon-minus icon-fw"/></button>
<button style="margin-left: -1px;" class="btn btn-xs bg-primary" {{action "scaleUp" target=service}} disabled={{not service.canScaleUp}}><i class="icon icon-plus icon-fw"/></button>
</div>
{{/if}}
</div>
<div class="vertical-middle">
<label class="acc-label vertical-middle p-0">{{t 'servicePage.multistat.created'}}</label>
{{date-calendar service.created}}

View File

@ -1,5 +1,5 @@
import Component from 'ember-component';
import injectService from 'ember-service/inject';
import { inject as service } from '@ember/service';
import observer from 'ember-metal/observer';
import { bind, once, scheduleOnce } from 'ember-runloop';
import CodeMirror from 'codemirror';
@ -9,7 +9,7 @@ export default Component.extend({
layout,
tagName: 'textarea',
codeMirror: injectService(),
codeMirror: service(),
didInsertElement() {
this._super(...arguments);
@ -17,7 +17,6 @@ export default Component.extend({
var cur = editor.getCursor();
var end = cur.ch, start = end;
var matched = this.get('codeMirror').getMatchedHint(editor.getValue(),editor);
console.log(matched);
return {list: matched.matchedArry, from: CodeMirror.Pos(cur.line, start - matched.index), to: CodeMirror.Pos(cur.line, end)};
});
this._codeMirror = this.get('codeMirror').fromTextArea(this.get('elementId'), this.get('element'));

View File

@ -1,16 +1,14 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { singleton } from 'pipeline/utils/pipelineStep';
export default Component.extend({
hintAry: null,
matchedArry: null,
positionX: 0,
positionY: 0,
activeIndex: 0,
codeMirror: service(),
didInsertElement(){
debugger
this.get('codeMirror').set('hintAry', this.get('hintAry'));
},
positionStyle: function(){
var positionX = this.get('positionX'), positionY=this.get('positionY');
return [
@ -31,6 +29,11 @@ export default Component.extend({
var hd = this.get('hidden');
return hd?'hide':'';
}.property('hidden'),
hiddenObserve: function () {
var hd = this.get('hidden');
let triggerInputEle = this.get('triggerInputEle');
hd&&this.$(triggerInputEle).focus()||this.$(triggerInputEle).blur();
}.observes('hidden'),
showHint(y,x){
this.set('positionX',x);
this.set('positionY',y);
@ -98,9 +101,8 @@ export default Component.extend({
return false;
},
actions: {
clickHint(val){
var triggerClickHint = this.get('triggerClickHint');
setHint(val){
var triggerClickHint = this.get('triggerClickHint');
triggerClickHint&&triggerClickHint(val)
var triggerInputEle = this.get('triggerInputEle');
if(!triggerInputEle){
@ -115,6 +117,11 @@ export default Component.extend({
$(triggerInputEle).trigger('change',newVal);
$(triggerInputEle).trigger('input',newVal);
}
this.set('hidden',true);
},
actions: {
clickHint(val){
this.setHint(val);
}
},
didRender(){
@ -137,9 +144,7 @@ export default Component.extend({
return pos;
}
}
var clickHiden = ()=>{
this.set('hidden',true);
};
var scrollPosition = ()=>{
var hd = this.get('hidden');
if(hd){
@ -148,17 +153,56 @@ export default Component.extend({
var originalCoordinates = this.get('originalCoordinates');
this.showHint(originalCoordinates.top-this.$(window).scrollTop(),originalCoordinates.left);
};
this.$(document).on('click.hint', clickHiden).on('scroll.hint', scrollPosition);
this.$(document).on('scroll.hint', scrollPosition);
},
willDestroyElement(){
this._super();
this.$(document).off('click.hint');
this.$(document).off('scroll.hint');
this.$(document).off('keyup.hint');
this.$(document).off('keyup.hint-return');
},
didInsertElement() {
this._super(...arguments);
this.$(document).on('keyup', 'input:not(.js-disable-hint)', (e) => {
singleton.hintAry = this.get('hintAry');
this.$(document).on('keyup.hint', 'input:not(.js-disable-hint)', (e) => {
$.fn.E_INPUT_HINT.startHint(e.target, ( /*hint*/ ) => {});
})
let $dropdownEle = this.$('.js-hint-dropdown');
let $activeLi ;
this.$(document).on('keyup.hint-return', (e) => {
let hiddenClass = this.get('hidden');
let activeIndex = this.get('activeIndex');
let matchedArry = this.get('matchedArry');
if(!hiddenClass){
switch(e.which){
//down
case 40:
activeIndex +=1;
if(activeIndex >= matchedArry.length){
activeIndex = matchedArry.length - 1;
}
this.set('activeIndex', activeIndex);
$activeLi = this.$('.js-hint-dropdown>li.active')[0];
$dropdownEle.scrollTop($activeLi.offsetTop - $dropdownEle.height() + 2*$activeLi.offsetHeight);
break;
// up
case 38:
activeIndex -=1;
if(activeIndex < 0 ){
activeIndex = 0;
}
this.set('activeIndex', activeIndex);
$activeLi = this.$('.js-hint-dropdown>li.active')[0];
$dropdownEle.scrollTop($activeLi.offsetTop - $dropdownEle.height());
break;
// enter
case 13:
this.setHint(matchedArry[activeIndex]);
break;
default: break;
}
}
});
}
});

View File

@ -1,10 +1,10 @@
<div style={{positionStyle}} class={{hiddenClass}} >
<ul class="dropdown-menu" style="position: static;display:inline-block;max-height: 200px;overflow: scroll">
<ul class="dropdown-menu js-hint-dropdown" style="position: static;display:inline-block;max-height: 200px;overflow: scroll">
{{#if loading}}
<li>loading...</li>
{{else}}
{{#each matchedArry as |hint|}}
<li {{action "clickHint" hint}}> <a href="#">{{hint}}</a> </li>
{{#each matchedArry as |hint index|}}
<li class="{{if (eq activeIndex index) 'active' ''}}" {{action "clickHint" hint}}> <a href="#">{{hint}}</a> </li>
{{/each}}
{{/if}}
</ul>

View File

@ -12,7 +12,6 @@ export default Component.extend(ThrottledResize, {
showProtip: true,
status: 'connecting',
socket: null,
pipeline: service(),
logHeight: 300,
globalStore: service(),
onlyCombinedLog: true,
@ -74,31 +73,6 @@ export default Component.extend(ThrottledResize, {
inst = this.get('instance');
var isFollow = ($body.scrollTop() + $body.outerHeight() + 10) >= body.scrollHeight;
// var logs = '';
// message.trim().split(/\n/).forEach((line) => {
// var match = line.match(/^\[?([^ \]]+)\]?\s?/);
// var dateStr, msg;
// if (match) {
// msg = line.substr(match[0].length);
// var date = new Date(match[1] * 1);
// dateStr = '<span class="log-date">' + Util.escapeHtml(date.toLocaleDateString()) + ' ' + Util.escapeHtml(date.toLocaleTimeString()) + ' </span>';
// } else {
// msg = line;
// dateStr = '<span class="log-date">Unknown Date</span>';
// }
// // body.insertAdjacentHTML('beforeend',
// // '<div class="log-msg">' +
// // dateStr +
// // AnsiUp.ansi_to_html(Util.escapeHtml(msg)) +
// // '</div>'
// // );
// logs += '<div class="log-msg">' +
// dateStr +
// AnsiUp.ansi_to_html(Util.escapeHtml(msg)) +
// '</div>';
// });
var logs = message;
var logsAry = inst.activityLogs;
@ -113,10 +87,7 @@ export default Component.extend(ThrottledResize, {
};
var activity = inst.activity;
// var params = `?activityId=${activity.id}&stageOrdinal=${inst.stageIndex}&stepOrdinal=${inst.stepIndex}`;
// var url = ("ws://" + window.location.host + this.get('pipeline.pipelinesEndpoint') + '/ws/log' + params);
// var socket = new WebSocket(url);
// this.set('socket', socket);
let fetchLog = ()=>{
if(inst.stageIndex===-1||inst.stepIndex===-1){
return

View File

@ -22,15 +22,7 @@ export default Component.extend({
dragDom: null,
model: null,
pipeline: null,
envvars: ['CICD_GIT_COMMIT',
'CICD_GIT_REPO_NAME',
'CICD_GIT_BRANCH',
'CICD_GIT_URL',
'CICD_PIPELINE_ID',
'CICD_PIPELINE_NAME',
'CICD_TRIGGER_TYPE',
'CICD_EXECUTION_ID',
'CICD_EXECUTION_SEQUENCE'].map(ele=>`\${${ele}}`),
envvars: '[]',
systemVars: null,
envvarsLoading: true,
modalService: service('modal'),
@ -39,6 +31,7 @@ export default Component.extend({
}.property('editable'),
init() {
this._super(...arguments);
this.set('envvars', JSON.parse(this.get('envvars')).map(ele=>`\${${ele}}`));
},
actions: {
dragStart: function(content, e) {

View File

@ -27,7 +27,7 @@ export default Component.extend({
let runScriptConfig = this.get('runScriptConfig');
let routeState = this.get('routeState');
if(runScriptConfig.image){
this.set('selectedType', 'Custom');
this.setLanguageEnvironment(runScriptConfig);
}else{
let label = this.get('languageToLabel')[routeState.language]|| 'Custom';
this.set('selectedType', label);
@ -37,6 +37,35 @@ export default Component.extend({
}
}
},
setLanguageEnvironment(runScriptConfig){
let image = runScriptConfig.image;
let selectedType = 'Custom';
if(runScriptConfig.isShell){
let splitedImage = image.split(':');
let imageName = splitedImage[0];
let imageTag = 'latest';
if(splitedImage[1]){
imageTag = splitedImage[1];
}
let environmentTypes = this.get('environmentTypes');
let shouldSelectedType = environmentTypes.find((ele)=>{
let eleImageName = ele.value.split(':')[0];
if(eleImageName === imageName){
return true
}
});
if(shouldSelectedType){
selectedType = shouldSelectedType.label;
let selectedImage = shouldSelectedType.value.split(':');
this.set('customImage',{
selectableTags: shouldSelectedType.version,
repo: selectedImage[0],
tag: selectedImage[1]
});
}
}
this.set('selectedType', selectedType);
},
selectedTypeObserve: function(){
let selectedType = this.get('selectedType');
if(selectedType !== 'Custom'){

View File

@ -69,7 +69,7 @@
<li {{action "changeTaskModel" true}}>
<a href="javascript:void(0);" class="{{if (eq runScriptConfig.isShell true) 'active' (if (eq modalOpts.type 'review') 'hide')}} ember-view">{{t 'newPipelineStep.stepType.task.shellScript'}}</a>
</li>
{{#if (eq selectedType 'custom')}}
{{#if (eq selectedType 'Custom')}}
<li {{action "changeTaskModel" false}}>
<a href="javascript:void(0);" class="{{if (eq runScriptConfig.isShell false) 'active' (if (eq modalOpts.type 'review') 'hide')}} ember-view">{{t 'newPipelineStep.stepType.task.customEntryPoint'}}</a>
</li>

View File

@ -32,7 +32,13 @@ export default Route.extend({
let accounts = globalStore.findAll('sourceCodeCredential');
let clusterPipeline = globalStore.find('clusterPipeline', `${clusterId}:${clusterId}`, {forceReload: true});
let projectDockerCredentials = projectStore.all('dockerCredential');
return hash({accounts, clusterPipeline, projectDockerCredentials} ).then(({accounts, clusterPipeline, projectDockerCredentials})=>{
return clusterPipeline.then((pipeline)=>{
clusterPipeline = pipeline;
return clusterPipeline.followLink('envvars')
}).then((envvars)=>{
return hash({accounts, clusterPipeline, projectDockerCredentials,envvars})
})
.then(({accounts, clusterPipeline, projectDockerCredentials, envvars})=>{
let pipeline = globalStore.createRecord({type:'pipeline', projectId , stages: this.get('precanStages')});
if(!accounts.content.length){
return {
@ -40,6 +46,7 @@ export default Route.extend({
accounts,
clusterPipeline,
projectDockerCredentials,
envvars,
repositories: [],
language: 'Custom'
};
@ -50,6 +57,7 @@ export default Route.extend({
accounts,
clusterPipeline,
projectDockerCredentials,
envvars,
repositories: res,
language: 'Custom'
}

View File

@ -9,6 +9,7 @@
<section class="pipeline-container">
{{pipeline-stages
clusterPipeline=model.clusterPipeline
envvars=model.envvars
pipeline=model.pipeline
stagesDraggable=true
accounts=model.accounts

View File

@ -24,18 +24,25 @@ export default Route.extend({
let accounts = globalStore.findAll('sourceCodeCredential');
let clusterPipeline = globalStore.find('clusterPipeline', `${clusterId}:${clusterId}`);
let projectDockerCredentials = projectStore.all('dockerCredential');
return hash({
return clusterPipeline.then((cPipeline)=>{
clusterPipeline = cPipeline;
return clusterPipeline.followLink('envvars')
}).then((envvars)=>{
return hash({
pipeline,
pipelineHistory,
accounts,
clusterPipeline,
projectDockerCredentials,
}).then(({
envvars
})
}).then(({
pipeline,
pipelineHistory,
accounts,
clusterPipeline,
projectDockerCredentials,
envvars
})=>{
var piplineObj;
if(params.mode === 'duplicate'){
@ -61,6 +68,7 @@ export default Route.extend({
accounts,
clusterPipeline,
projectDockerCredentials,
envvars,
repositories: [],
}
}else{
@ -73,6 +81,7 @@ export default Route.extend({
accounts,
clusterPipeline,
projectDockerCredentials,
envvars,
repositories: res,
}
})

View File

@ -16,6 +16,7 @@
<section class="pipeline-container">
{{pipeline-stages
clusterPipeline=model.clusterPipeline
envvars=model.envvars
pipeline=model.pipeline
stagesDraggable=false
accounts=model.accounts

View File

@ -1,20 +1,14 @@
import CodeMirror from 'codemirror';
import Service from 'ember-service';
import { singleton } from 'pipeline/utils/pipelineStep';
import { set, get } from '@ember/object';
export default Service.extend({
init() {
this._super(...arguments);
this._instances = Object.create(null);
},
hintAry: ['CICD_GIT_COMMIT',
'CICD_GIT_REPO_NAME',
'CICD_GIT_BRANCH',
'CICD_GIT_URL',
'CICD_PIPELINE_ID',
'CICD_PIPELINE_NAME',
'CICD_TRIGGER_TYPE',
'CICD_EXECUTION_ID',
'CICD_EXECUTION_SEQUENCE'].map(ele=>`\${${ele}}`),
fromTextArea(id, textarea) {
return this.registerInstance(id, CodeMirror.fromTextArea(textarea));
},
@ -37,7 +31,7 @@ export default Service.extend({
delete this._instances[id];
},
getMatchedHint(value, editor) {
var hintAry = this.get('hintAry');
var hintAry = singleton.hintAry;
var cur = editor.getCursor();
var cursorPosition = cur.ch;
var cursorValue = editor.getLine(cur.line).slice(0, cursorPosition);

View File

@ -1,7 +1,6 @@
import Service from '@ember/service';
import { inject as service } from '@ember/service';
export default Service.extend({
globalStore: service(),
scope: service(),

View File

@ -1,5 +1,9 @@
const DEFAULT_REGISTRY = 'index.docker.io';
export let singleton = {
hintAry: []
}
export function analyzeImageRepo (images) {
if(!images){
return '';
@ -35,6 +39,7 @@ export function analyzeImageRepo (images) {
return output;
}
export const environmentTypes = [{
label: 'C',
value: 'gcc:latest',

View File

@ -20,12 +20,12 @@ export default Component.extend(ManageLabels, {
},
{
name: 'name',
sort: ['key'],
sort: ['name'],
translationKey: 'generic.name',
},
{
name: 'image',
sort: ['value','key'],
name: 'displayImage',
sort: ['displayImage'],
translationKey: 'generic.image',
},
{

View File

@ -26,8 +26,8 @@
<td data-title="{{dt.name}}">
{{inst.name}}
</td>
<td data-title="{{dt.image}}">
{{inst.image}}
<td data-title="{{dt.displayImage}}">
{{inst.displayImage}}
</td>
<td data-title="{{dt.displayIp}}">
{{inst.displayIp}}

View File

@ -56,11 +56,6 @@
{{/each}}
</tbody>
</table>
{{#if ary.length}}
<div class="protip mb-5">
{{t 'formKeyValue.protip'}}
</div>
{{/if}}
{{else}}
{{#unless editing}}
<div>{{t 'generic.none'}}</div>
@ -68,6 +63,11 @@
{{/if}}
{{#if (and editing allowAdd)}}
{{#if ary.length}}
<div class="protip mb-5">
{{t 'formKeyValue.protip'}}
</div>
{{/if}}
<div>
<button class="btn bg-link icon-btn p-0" {{action "add"}}>
<span class="darken"><i class="icon icon-plus text-small"/></span>

View File

@ -37,3 +37,7 @@ li.CodeMirror-hint-active {
background: #08f;
color: white;
}
.CodeMirror-hints > li:hover {
background: #08f;
color: white;
}