all components moved to common js

This commit is contained in:
Vladimir Polyakov 2015-12-12 00:01:03 +03:00
parent 5879a7caf3
commit a36f9cf955
48 changed files with 255 additions and 37338 deletions

View File

@ -4,6 +4,8 @@ var React = require('react'),
ReactDOM = require('react-dom'),
App = require('./components/app'),
Dashboard = require('./components/dashboard'),
ProjectView = require('./components/projects/view'),
BuildView = require('./components/builds/view'),
connect = require('./connect'),
resources = require('./resources'),
Router = require('react-router');
@ -17,18 +19,13 @@ var routes = (
name: 'dashboard',
path: '/',
handler: Dashboard
})
//Route({
//name: 'project',
//path: 'projects/:name',
//handler: Components.Project.View
//}),
//Route({name: 'build', path: 'builds/:id', handler: Components.Build.View}),
//Route({
//name: 'buildLog',
//path: 'builds/:buildId/log',
//handler: Components.BuildLog
//})
}),
Route({
name: 'project',
path: 'projects/:name',
handler: ProjectView
}),
Route({name: 'build', path: 'builds/:id', handler: BuildView})
)
);

View File

@ -9,6 +9,7 @@ var React = require('react'),
var Component = React.createClass({
componentDidMount: function() {
console.log('read all projects in component');
console.log(ProjectActions);
ProjectActions.readAll();
},
render: function() {

View File

@ -0,0 +1,51 @@
'use strict';
var _ = require('underscore'),
React = require('react'),
Router = require('react-router'),
Reflux = require('reflux'),
ProjectActions = require('../../../actions/project'),
BuildActions = require('../../../actions/build'),
buildStore = require('../../../stores/build'),
Terminal = require('../../terminal'),
BuildSidebar = require('./sidebar'),
CommonComponents = require('../../common'),
template = require('./index.jade');
var Component = React.createClass({
mixins: [Reflux.ListenerMixin],
statics: {
willTransitionTo: function(transition, params, query) {
BuildActions.read(Number(params.id));
}
},
componentDidMount: function() {
this.listenTo(buildStore, this.updateBuild);
},
updateBuild: function(build) {
if (build) {
BuildActions.readAll({projectName: build.project.name});
}
this.setState({build: build});
},
render: template.locals(_({
Terminal: Terminal,
Link: Router.Link,
BuildSidebar: BuildSidebar
}).extend(CommonComponents)),
getInitialState: function() {
return {
build: null,
showConsole: false
};
},
toggleConsole: function() {
var consoleState = !this.state.showConsole;
if (consoleState) {
BuildActions.readTerminalOutput(this.state.build);
}
this.setState({showConsole: consoleState});
}
});
module.exports = Component;

View File

@ -0,0 +1,27 @@
'use strict';
var _ = require('underscore'),
React = require('react'),
Reflux = require('reflux'),
Router = require('react-router'),
buildsStore = require('../../../../stores/builds'),
template = require('./index.jade'),
CommonComponents = require('../../../common');
module.exports = React.createClass({
mixins: [
Reflux.connectFilter(buildsStore, 'items', function(items) {
var projectName = this.props.projectName;
if (projectName) {
return _(items).filter(function(item) {
return item.project && item.project.name === projectName;
});
} else {
return items;
}
})
],
render: template.locals(_({
Link: Router.Link
}).extend(CommonComponents))
});

View File

@ -2,7 +2,7 @@
var React = require('react'),
Router = require('react-router'),
ProjectsSelector = require('../projects-selector'),
ProjectsSelector = require('../projects/selector'),
template = require('./index.jade');
var Component = React.createClass({

View File

@ -4,10 +4,10 @@ var React = require('react'),
ReactDOM = require('react-dom'),
Router = require('react-router'),
Reflux = require('reflux'),
ProjectActions = require('../../actions/project'),
projectsStore = require('../../stores/project'),
ProjectActions = require('../../../actions/project'),
projectsStore = require('../../../stores/projects'),
template = require('./index.jade'),
Scm = require('../common/scm');
Scm = require('../../common/scm');
module.exports = React.createClass({
mixins: [Reflux.ListenerMixin, Router.Navigation],

View File

@ -0,0 +1,42 @@
'use strict';
var _ = require('underscore'),
React = require('react'),
Reflux = require('reflux'),
ProjectActions = require('../../../actions/project'),
BuildActions = require('../../../actions/build'),
projectStore = require('../../../stores/project'),
Builds = require('../../builds/list'),
CommonComponents = require('../../common'),
template = require('./index.jade');
module.exports = React.createClass({
mixins: [
Reflux.connectFilter(projectStore, 'project', function(project) {
if (project.name === this.props.params.name) {
return project;
} else {
if (this.state) {
return this.state.project;
} else {
return projectStore.getInitialState();
}
}
})
],
statics: {
willTransitionTo: function(transition, params, query) {
ProjectActions.read({name: params.name});
BuildActions.readAll({projectName: params.name});
}
},
onBuildProject: function() {
if (this.state.project.name) {
console.log(this.state.project.name);
ProjectActions.run(this.state.project.name);
}
},
render: template.locals(
_({Builds: Builds}).extend(CommonComponents)
)
});

View File

@ -0,0 +1,100 @@
'use strict';
var _ = require('underscore'),
React = require('react'),
Reflux = require('reflux'),
terminalStore = require('../../stores/terminal'),
ansiUp = require('ansi_up'),
template = require('./index.jade');
var Component = React.createClass({
mixins: [Reflux.ListenerMixin],
shouldScrollBottom: true,
data: [],
linesCount: 0,
componentDidMount: function() {
this.listenTo(terminalStore, this.updateItems);
var node = document.getElementsByClassName('terminal')[0];
this.initialScrollPosition = node.getBoundingClientRect().top;
window.onscroll = this.onScroll;
},
componentWillUnmount: function() {
window.onscroll = null;
},
prepareRow: function(row) {
return ansiUp.ansi_to_html(row.replace('\r', ''));
},
prepareOutput: function(output) {
var self = this;
return output.map(function(row) {
return self.prepareRow(row);
});
},
getTerminal: function() {
return document.getElementsByClassName('terminal')[0];
},
getBody: function() {
return document.getElementsByTagName('body')[0];
},
onScroll: function() {
var node = this.getTerminal(),
body = this.getBody();
this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
node.offsetHeight + this.initialScrollPosition;
},
ensureScrollPosition: function() {
if (this.shouldScrollBottom) {
var node = this.getTerminal(),
body = this.getBody();
body.scrollTop = this.initialScrollPosition + node.offsetHeight;
}
},
makeCodeLineContent: function(line) {
return '<span class="code-line_counter">' + '</span>' +
'<div class="code-line_body">' + this.prepareRow(line) + '</div>';
},
makeCodeLine: function(line, index) {
return '<div class="code-line" data-number="' + index + '">' +
this.makeCodeLineContent(line) + '</div>';
},
renderBuffer: _.throttle(function() {
var data = this.data,
currentLinesCount = data.length,
terminal = document.getElementsByClassName('terminal_code')[0],
rows = terminal.childNodes;
if (rows.length) {
// replace our last node
var index = this.linesCount - 1;
rows[index].innerHTML = this.makeCodeLineContent(data[index]);
}
var self = this;
terminal.insertAdjacentHTML('beforeend',
_(data.slice(this.linesCount)).map(function(line, index) {
return self.makeCodeLine(line, self.linesCount + index);
}).join('')
);
this.linesCount = currentLinesCount;
this.ensureScrollPosition();
}, 100),
updateItems: function(build) {
// listen just our console update
if (build.buildId === this.props.build) {
this.data = build.data;
this.renderBuffer();
}
},
shouldComponentUpdate: function() {
return false;
},
render: template
});
module.exports = Component;

View File

@ -4,6 +4,7 @@ var Reflux = require('reflux'),
ProjectActions = require('../actions/project'),
resource = require('../resources').projects;
console.log('resource', resource);
var Store = Reflux.createStore({
listenables: ProjectActions,
onRun: function(projectName) {
@ -12,6 +13,7 @@ var Store = Reflux.createStore({
});
},
onReadAll: function(params) {
console.log('on read all in store');
var self = this;
resource.sync('readAll', params, function(err, projects) {
if (err) throw err;

View File

@ -3,7 +3,7 @@
var _ = require('underscore'),
Reflux = require('reflux'),
BuildActions = require('../actions/build'),
connect = require('app/connect');
connect = require('../connect').data;
var Store = Reflux.createStore({
listenables: BuildActions,

View File

@ -1,7 +1,7 @@
'use strict';
var _ = require('underscore'),
sharedUtils = require('../static/js/shared/utils');
sharedUtils = require('../app/utils');
_(exports).extend(sharedUtils);

View File

@ -9,8 +9,8 @@
"makeTestRepos": "rm -rf test/repos/{mercurial,git}; cd test/repos/ && tar -xf mercurial.tar.gz && tar -xf git.tar.gz",
"test": "npm run makeTestRepos && mocha --bail --reporter=spec --timeout 4000",
"watchLess": "catw -c 'lessc static/css/index.less' 'static/css/**/*.less' > static/css/index.css",
"watchJs": "watchify app/app.js -t react-jade -o static/js/app.build.js -dv",
"dev": "npm run watchJs & nodemon app.js",
"watchJs": "watchify app/app.js -t ./transforms/jade.js -o static/js/app.build.js -dv",
"dev": "npm run watchLess & npm run watchJs & nodemon app.js",
"sync": "npm install && npm prune && bower install && bower prune",
"buildJs": "r.js -o static/js/requirejs/buid.js",
"buildClean": "rm static/index.html",
@ -44,13 +44,22 @@
},
"homepage": "https://github.com/node-ci/nci",
"dependencies": {
"ansi_up": "^1.3.0",
"bootstrap": "^3.3.6",
"browserify": "^12.0.1",
"chokidar": "1.0.3",
"colors": "1.1.2",
"cron": "1.0.9",
"data.io": "0.3.0",
"font-awesome": "^4.5.0",
"history": "^1.13.1",
"moment": "^2.10.6",
"nlevel": "1.0.3",
"node-static": "0.7.6",
"react-dom": "^0.14.3",
"react-jade": "^2.5.0",
"react-router": "^0.13.5",
"reflux": "^0.3.0",
"socket.io": "1.3.5",
"socket.io-client": "^1.3.7",
"through": "2.3.6",
@ -58,20 +67,16 @@
"underscore": "1.8.3"
},
"devDependencies": {
"bower": "1.4.1",
"catw": "^1.0.1",
"expect.js": "0.3.1",
"gulp": "3.8.11",
"gulp-less": "3.0.3",
"gulp-nodemon": "2.0.3",
"jade": "1.11.0",
"main-bower-files": "2.7.0",
"jshint": "^2.9.1-rc1",
"memdown": "1.1.0",
"mocha": "1.18.2",
"nci-yaml-reader": "0.1.0",
"nodemon": "1.3.7",
"nrun": "0.1.4",
"requirejs": "2.1.19",
"sinon": "1.14.1"
"sinon": "1.14.1",
"watchify": "^3.6.1"
}
}

View File

@ -1,15 +1,15 @@
/*@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,700&subset=latin,cyrillic-ext);*/
@bowerPath: "../js/libs";
@libPath: "../../node_modules";
// bootstrap
@import "@{bowerPath}/bootstrap/less/bootstrap.less";
@import "@{libPath}/bootstrap/less/bootstrap.less";
/*//flatly*/
@import "./sources/common/variables-flatly.less";
//font-awesome
@import "@{bowerPath}/font-awesome/less/font-awesome.less";
@import "@{libPath}/font-awesome/less/font-awesome.less";
//variables
@import "./sources/common/variables.less";

File diff suppressed because one or more lines are too long

View File

@ -1,42 +0,0 @@
'use strict';
define([
'react',
'react-router',
'templates/app/components/app/index',
'app/components/index',
'app/actions/project', 'app/actions/build'
], function(
React,
Router,
template,
Components,
ProjectActions, BuildActions
) {
var Route = React.createFactory(Router.Route),
DefaultRoute = React.createFactory(Router.DefaultRoute);
var routes = (
Route({handler: Components.App},
Route({name: 'dashboard', path: '/', handler: Components.Dashboard}),
Route({
name: 'project',
path: 'projects/:name',
handler: Components.Project.View
}),
Route({name: 'build', path: 'builds/:id', handler: Components.Build.View}),
Route({
name: 'buildLog',
path: 'builds/:buildId/log',
handler: Components.BuildLog
})
)
);
Router.run(routes, Router.HistoryLocation, function(Handler) {
React.render(
React.createElement(Handler),
document.getElementById('content')
);
});
});

View File

@ -1,6 +0,0 @@
div
Header()
.container-fluid
.page-wrapper
RouteHandler()

View File

@ -1,24 +0,0 @@
'use strict';
define([
'react',
'react-router',
'app/actions/project',
'app/components/header/index',
'templates/app/components/app/index'
], function(React, Router, ProjectActions, Header, template) {
template = template.locals({
Link: Router.Link,
Header: Header,
RouteHandler: Router.RouteHandler
});
var Component = React.createClass({
componentWillMount: function() {
ProjectActions.readAll();
},
render: template
});
return Component;
});

View File

@ -1,30 +0,0 @@
- var buildId = this.props.params.buildId;
- var total = this.state.data.total;
- var output = this.state.data.output;
div
| build:
span= buildId
div
| lines in total:
span= total
div
| from:
input(type="text", value=this.state.from, onChange=this.onFromChange)
br
.terminal(style="width: 900px; float: left;")
.terminal_code(ref="code")!= output
div.terminal-virtual-scroll(
style="width: 15px; height: 320px; overflow: scroll; float: clear;",
onScroll=this.onVirtualScroll
)
- var height = total * 15;
div(style="height: #{height}px;")
div
| virtual scroll top:
span= this.state.virtualScrollTop

View File

@ -1,78 +0,0 @@
'use strict';
define([
'react', 'reflux', 'app/actions/buildLog', 'app/stores/buildLog',
'ansi_up', 'underscore', 'templates/app/components/buildLog/index',
'jquery'
], function(
React, Reflux, BuildLogActions, buildLogStore,
ansiUp, _, template,
$
) {
var chunkSize = 40;
return React.createClass({
mixins: [
Reflux.connectFilter(buildLogStore, 'data', function(data) {
data.output = _(data.lines).pluck('text').join('<br>');
data.output = data.output.replace(
/(.*)\n/gi,
'<span class="terminal_code_newline">$1</span>'
);
data.output = ansiUp.ansi_to_html(data.output);
return data;
})
],
statics: {
willTransitionTo: function(transition, params, query) {
BuildLogActions.getTail({buildId: params.buildId, length: chunkSize});
}
},
onFromChange: function(event) {
var from = Number(event.target.value);
this.setState({from: from});
BuildLogActions.getLines({
buildId: this.props.params.buildId,
from: from,
to: from + chunkSize - 1
});
},
onVirtualScroll: function(event) {
this.virtualScrollTop = $(event.target).scrollTop();
this.setState({virtualScrollTop: this.virtualScrollTop});
var isDown = this.virtualScrollTop > this.lastVirtualScrollTop;
var inc = isDown ? 15 : -15;
var scrollTop = $('.terminal_code').scrollTop(),
viewHeight = $('.terminal_code').height(),
contentHeight = $('.terminal_code div:first').height();
if (
(isDown && scrollTop + viewHeight + inc < contentHeight) ||
(!isDown && scrollTop + inc > 0)
) {
$('.terminal_code').scrollTop(scrollTop + inc);
} else {
var lines = this.state.data.lines,
line = lines[isDown ? lines.length - 1 : 0],
from = isDown ? line.number : line.number - chunkSize;
from = from < 0 ? 1 : from;
console.log('>>> end = ', line, from);
BuildLogActions.getLines({
buildId: this.props.params.buildId,
from: from,
to: from + chunkSize - 1
});
}
this.lastVirtualScrollTop = this.virtualScrollTop;
},
render: template
});
});

View File

@ -1,33 +0,0 @@
'use strict';
define([
'underscore',
'react', 'react-router',
'app/stores/builds', 'reflux',
'templates/app/components/buildSidebar/index', 'app/components/common/index',
], function(
_,
React, Router,
buildsStore, Reflux,
template, CommonComponents
) {
template = template.locals(_({
Link: Router.Link
}).extend(CommonComponents));
return React.createClass({
mixins: [
Reflux.connectFilter(buildsStore, 'items', function(items) {
var projectName = this.props.projectName;
if (projectName) {
return _(items).filter(function(item) {
return item.project && item.project.name === projectName;
});
} else {
return items;
}
})
],
render: template
});
});

View File

@ -1,13 +0,0 @@
'use strict';
define([
'app/components/builds/item',
'app/components/builds/list',
'app/components/builds/view'
], function(Item, List, View) {
return {
Item: Item,
List: List,
View: View
};
});

View File

@ -1,93 +0,0 @@
mixin statusText(build)
if build.status === 'in-progress'
span in progress
if build.status === 'queued'
span queued
if build.status === 'done'
span done
if build.status === 'error'
span error
- var build = this.props.build;
.build(class="")
.build_content
.build_status
.status(class="status__#{build.status}")
div.build_header
if build.project
span
Scm(scm=build.project.scm.type)
|
Link(to="project", params={name: build.project.name})
span= build.project.name
|
if build.number
span(style={fontSize: '15px', color: '#a6a6a6'}) build
|
if build.status !== 'queued'
Link(to="build", params={id: build.id})
span #
span= build.number
else
span #
span= build.number
if build.waitReason
span (
span= build.waitReason
span , waiting)
if build.status === 'in-progress' && build.currentStep
span (
span= build.currentStep
span )
div
if build.endDate
span.build_info
i.fa.fa-fw.fa-clock-o
| finished
DateTime(value=build.endDate)
|
Duration(value=(build.endDate - build.startDate), withSuffix=true)
else
if build.startDate
span.build_info
i.fa.fa-fw.fa-clock-o
| started
DateTime(value=build.startDate)
else
span.build_info
i.fa.fa-fw.fa-clock-o
| queued
DateTime(value=build.createDate)
|
if build.scm
span.build_info
i.fa.fa-fw.fa-comment-o
|
span= utils.prune(build.scm.rev.comment, 40)
|
.build_controls
if build.completed
.build_controls_buttons
a.btn.btn-sm.btn-default(href="javascript:void(0);", onClick=this.onRebuildProject(build.project.name))
i.fa.fa-fw.fa-repeat(title="Rebuild")
|
| Build again
if build.status === 'in-progress'
.build_controls_progress
if build.project.avgBuildDuration
Progress(build=build)
if build.status === 'queued'
.build_controls_buttons
a.btn.btn-sm.btn-default(href="javascript:void(0);", onClick=this.onCancelBuild(build.id))
i.fa.fa-fw.fa-times(title="Cancel build")
|
| Cancel build

View File

@ -1,47 +0,0 @@
'use strict';
define([
'react', 'react-router', 'app/actions/project',
'app/actions/build', 'templates/app/components/builds/item',
'app/components/terminal/terminal', 'app/components/common/index',
'app/utils'
], function(
React, Router, ProjectActions,
BuildActions, template,
TerminalComponent, CommonComponents,
utils
) {
template = template.locals({
DateTime: CommonComponents.DateTime,
Duration: CommonComponents.Duration,
Progress: CommonComponents.Progress,
Scm: CommonComponents.Scm,
Terminal: TerminalComponent,
Link: Router.Link,
utils: utils
});
var Component = React.createClass({
getInitialState: function() {
return {
showTerminal: false
};
},
onRebuildProject: function(projectName) {
ProjectActions.run(projectName)
},
onCancelBuild: function(buildId) {
BuildActions.cancel(buildId);
},
onShowTerminal: function(build) {
this.setState({showTerminal: !this.state.showTerminal});
BuildActions.readTerminalOutput(this.props.build);
},
onBuildSelect: function(buildId) {
console.log('on build select');
},
render: template
});
return Component;
});

View File

@ -1,6 +0,0 @@
.builds
if !this.state.items.length
p Build history is empty
- console.log('>>>> builds = ', JSON.stringify(this.state.items).length, this.state.items)
each build, index in this.state.items
Item(build=build, key=build.id)

View File

@ -1,32 +0,0 @@
'use strict';
define([
'react',
'reflux',
'underscore',
'./item',
'app/stores/builds',
'templates/app/components/builds/list'
], function(React, Reflux, _, Item, buildsStore, template) {
template = template.locals({
Item: Item
});
var Component = React.createClass({
mixins: [
Reflux.connectFilter(buildsStore, 'items', function(items) {
var projectName = this.props.projectName;
if (projectName) {
return _(items).filter(function(item) {
return item.project && item.project.name === projectName;
});
} else {
return items;
}
})
],
render: template
});
return Component;
});

View File

@ -1,59 +0,0 @@
'use strict';
define([
'react',
'react-router',
'reflux',
'app/actions/build',
'app/stores/build',
'app/components/terminal/terminal',
'app/components/buildSidebar/index',
'templates/app/components/builds/view',
'app/components/common/index'
], function(
React, Router, Reflux, BuildActions, buildStore, TerminalComponent,
BuildSidebar, template, CommonComponents
) {
template = template.locals({
DateTime: CommonComponents.DateTime,
Duration: CommonComponents.Duration,
Scm: CommonComponents.Scm,
Terminal: TerminalComponent,
Link: Router.Link,
BuildSidebar: BuildSidebar
});
var Component = React.createClass({
mixins: [Reflux.ListenerMixin],
statics: {
willTransitionTo: function(transition, params, query) {
BuildActions.read(Number(params.id));
}
},
componentDidMount: function() {
this.listenTo(buildStore, this.updateBuild);
},
updateBuild: function(build) {
if (build) {
BuildActions.readAll({projectName: build.project.name});
}
this.setState({build: build});
},
render: template,
getInitialState: function() {
return {
build: null,
showConsole: false
};
},
toggleConsole: function() {
var consoleState = !this.state.showConsole;
if (consoleState) {
BuildActions.readTerminalOutput(this.state.build);
}
this.setState({showConsole: consoleState});
}
});
return Component;
});

View File

@ -1,5 +0,0 @@
.main-row
.row
.col-md-8.col-sm-12
h2 Builds history
BuildsList()

View File

@ -1,25 +0,0 @@
'use strict';
define([
'react',
'react-router',
'app/actions/project',
'app/actions/build',
'app/components/builds/list',
'templates/app/components/dashboard/index'
], function(React, Router, ProjectActions, BuildActions, BuildsList, template) {
template = template.locals({
Link: Router.Link,
BuildsList: BuildsList
});
var Component = React.createClass({
componentWillMount: function() {
ProjectActions.readAll();
BuildActions.readAll();
},
render: template
});
return Component;
});

View File

@ -1,20 +0,0 @@
'use strict';
define([
'app/components/projects/index', 'app/components/builds/index',
'app/components/app/index', 'app/components/header/index',
'app/components/dashboard/index', 'app/components/buildLog/index'
], function(
ProjectsComponents, BuildsComponents,
App, Header,
Dashboard, BuildLogComponent
) {
return {
App: App,
Header: Header,
Project: ProjectsComponents,
Build: BuildsComponents,
Dashboard: Dashboard,
BuildLog: BuildLogComponent
};
});

View File

@ -1,11 +0,0 @@
'use strict';
define([
'app/components/projects/selector/index',
'app/components/projects/view/index'
], function(Selector, View) {
return {
Selector: Selector,
View: View
};
});

View File

@ -1,24 +0,0 @@
.projects-selector(href="javascript:void(0);")
if !this.state.showSearch
span.projects-selector_preview(onClick=this.onSearchProject)
i.fa.fa-fw.fa-bars
span.projects-selector_preview_text Select a project...
else
input.projects-selector_input(
type="text",
value=this.state.searchQuery,
onChange=this.onSearchChange,
ref=this.onInputMount,
onBlur=this.onBlurSearch
)
ul.projects-selector_items
each project in this.state.projects
li.projects-selector_item(key=project.name)
Link.projects-selector_item_link(to="project", params={name: project.name}, onMouseDown=this.onSelectProject(project.name))
Scm(scm=project.scm.type)
span
span= project.name
a.projects-selector_item_run(href="javascript:void(0);", onMouseDown=this.onRunProject(project.name))
i.fa.fa-fw.fa-play

View File

@ -1,55 +0,0 @@
'use strict';
define([
'react', 'react-router', 'reflux', 'app/actions/project',
'app/stores/projects',
'app/components/common/scm/index',
'templates/app/components/projects/selector/index'
], function(React, Router, Reflux, ProjectActions, projectsStore, Scm,
template
) {
template = template.locals({
Link: Router.Link,
Scm: Scm
});
return React.createClass({
mixins: [Reflux.ListenerMixin, Router.Navigation],
componentDidMount: function() {
this.listenTo(projectsStore, this.updateItems);
},
getInitialState: function() {
return {
showSearch: false
};
},
onRunProject: function(projectName) {
ProjectActions.run(projectName)
this.setState({showSearch: false});
},
onSelectProject: function(name) {
this.transitionTo('project', {name: name});
},
updateItems: function(projects) {
this.setState({projects: projects});
},
onSearchProject: function() {
this.setState({showSearch: true});
},
onInputMount: function(component) {
var node = React.findDOMNode(component);
if (node) {
node.focus();
}
},
onBlurSearch: function() {
this.setState({showSearch: false});
},
onSearchChange: function(event) {
var query = event.target.value;
this.setState({searchQuery: query});
ProjectActions.readAll({nameQuery: query});
},
render: template,
});
});

View File

@ -1,51 +0,0 @@
'use strict';
define([
'react', 'reflux',
'app/actions/project',
'app/actions/build',
'app/stores/project',
'app/components/builds/list',
'app/components/common/scm/index',
'templates/app/components/projects/view/index',
'app/components/common/index',
'bootstrap/dropdown'
], function(React, Reflux, ProjectActions, BuildActions,
projectStore, Builds, Scm, template, CommonComponents
) {
template = template.locals({
Builds: Builds,
Scm: Scm,
DateTime: CommonComponents.DateTime,
Duration: CommonComponents.Duration
});
return React.createClass({
mixins: [
Reflux.connectFilter(projectStore, 'project', function(project) {
if (project.name === this.props.params.name) {
return project;
} else {
if (this.state) {
return this.state.project;
} else {
return projectStore.getInitialState();
}
}
})
],
statics: {
willTransitionTo: function(transition, params, query) {
ProjectActions.read({name: params.name});
BuildActions.readAll({projectName: params.name});
}
},
onBuildProject: function() {
if (this.state.project.name) {
console.log(this.state.project.name);
ProjectActions.run(this.state.project.name);
}
},
render: template
});
});

View File

@ -1,9 +0,0 @@
'use strict';
define([
'app/components/terminal/terminal',
], function(Console) {
return {
Console: Console
};
});

View File

@ -1,102 +0,0 @@
'use strict';
define([
'underscore',
'react',
'reflux',
'app/stores/terminal',
'ansi_up',
'templates/app/components/terminal/terminal',
], function(_, React, Reflux, terminalStore, ansiUp, template) {
var Component = React.createClass({
mixins: [Reflux.ListenerMixin],
shouldScrollBottom: true,
data: [],
linesCount: 0,
componentDidMount: function() {
this.listenTo(terminalStore, this.updateItems);
var node = document.getElementsByClassName('terminal')[0];
this.initialScrollPosition = node.getBoundingClientRect().top;
window.onscroll = this.onScroll;
},
componentWillUnmount: function() {
window.onscroll = null;
},
prepareRow: function(row) {
return ansiUp.ansi_to_html(row.replace('\r', ''));
},
prepareOutput: function(output) {
var self = this;
return output.map(function(row) {
return self.prepareRow(row);
});
},
getTerminal: function() {
return document.getElementsByClassName('terminal')[0];
},
getBody: function() {
return document.getElementsByTagName('body')[0];
},
onScroll: function() {
var node = this.getTerminal(),
body = this.getBody();
this.shouldScrollBottom = window.innerHeight + body.scrollTop >=
node.offsetHeight + this.initialScrollPosition;
},
ensureScrollPosition: function() {
if (this.shouldScrollBottom) {
var node = this.getTerminal(),
body = this.getBody();
body.scrollTop = this.initialScrollPosition + node.offsetHeight;
}
},
makeCodeLineContent: function(line) {
return '<span class="code-line_counter">' + '</span>' +
'<div class="code-line_body">' + this.prepareRow(line) + '</div>';
},
makeCodeLine: function(line, index) {
return '<div class="code-line" data-number="' + index + '">' +
this.makeCodeLineContent(line) + '</div>';
},
renderBuffer: _.throttle(function() {
var data = this.data,
currentLinesCount = data.length,
terminal = document.getElementsByClassName('terminal_code')[0],
rows = terminal.childNodes;
if (rows.length) {
// replace our last node
var index = this.linesCount - 1;
rows[index].innerHTML = this.makeCodeLineContent(data[index]);
}
var self = this;
terminal.insertAdjacentHTML('beforeend',
_(data.slice(this.linesCount)).map(function(line, index) {
return self.makeCodeLine(line, self.linesCount + index);
}).join('')
);
this.linesCount = currentLinesCount;
this.ensureScrollPosition();
}, 100),
updateItems: function(build) {
// listen just our console update
if (build.buildId === this.props.build) {
this.data = build.data;
this.renderBuffer();
}
},
shouldComponentUpdate: function() {
return false;
},
render: template
});
return Component;
});

View File

@ -1,3 +0,0 @@
p 123
Terminal(lines=this.state.lines)

View File

@ -1,19 +0,0 @@
'use strict';
define([
'react',
'../terminal',
'templates/app/components/terminal/test/index'
], function(React, TerminalComponent, template) {
template = template.locals({
Terminal: TerminalComponent
});
return React.createClass({
getInitialState: function() {
return {
lines: [1, 2, 3]
};
},
render: template
});
});

View File

@ -1,29 +0,0 @@
'use strict';
define(['_dataio'], function(dataio) {
return function(socket) {
var connect = dataio(socket);
/*
* Extend Resource
*/
var resource = connect.resource('__someResource__'),
resourcePrototype = Object.getPrototypeOf(resource);
resourcePrototype.disconnect = function() {
this.socket.disconnect();
this.socket.removeAllListeners();
};
resourcePrototype.connect = function() {
this.socket.connect();
};
resourcePrototype.reconnect = function() {
this.disconnect();
this.connect();
};
return connect;
};
});

View File

@ -1,17 +0,0 @@
({
mainConfigFile: 'development.js',
baseUrl: '../',
paths: {
socketio: (
'../../node_modules/socket.io/node_modules/' +
'socket.io-client/socket.io'
),
_dataio: '../../node_modules/data.io/data.io',
},
name: 'app/app',
preserveLicenseComments: false,
optimize: 'uglify2',
useStrict: true,
out: '../../js/app.build.js'
});

View File

@ -1,21 +0,0 @@
require.config({
baseUrl: '/js',
paths: {
socketio: '/socket.io/socket.io',
_dataio: '/data.io',
underscore: 'libs/underscore/underscore',
react: 'libs/react/react-with-addons',
'react-router': 'libs/react-router/build/umd/ReactRouter',
reflux: 'libs/reflux/dist/reflux',
jquery: 'libs/jquery/jquery',
ansi_up: 'libs/ansi_up/ansi_up',
moment: 'libs/moment/moment',
'bootstrap/collapse': 'libs/bootstrap/js/collapse',
'bootstrap/dropdown': 'libs/bootstrap/js/dropdown'
},
shim: {
'bootstrap/collapse': ['jquery'],
'bootstrap/dropdown': ['jquery']
}
});

View File

@ -1,3 +0,0 @@
require.config({
});

View File

@ -1,32 +0,0 @@
'use strict';
(function(root, factory) {
if (typeof module !== 'undefined' && module.exports) {
// CommonJS
module.exports = factory();
} else if (typeof define === 'function' && define.amd) {
// AMD
define(function() {
return factory();
});
}
}(this, function() {
var utils = {};
utils.prune = function(str, length) {
var result = '',
words = str.split(' ');
do {
result += words.shift() + ' ';
} while (words.length && result.length < length);
return result.replace(/ $/, words.length ? '...' : '');
};
return utils;
}));

View File

@ -4,26 +4,6 @@ html
title nci
link(href="/css/index.css", rel="stylesheet", type="text/css")
//-if env === 'development'
//-script(type="text/javascript", src="/js/libs/requirejs/require.js")
//-else
//-script
//-include ../static/js/libs/almond/almond.js
//-if env === 'development'
//-script
//-include ../static/js/requirejs/development.js
//-else
//-script
//-include ../static/js/requirejs/production.js
//-script
//-include ../static/js/app.build.js
//-script(type="text/javascript").
//-require(['app/app']);
body
#content