More front end work, stages and log entries

This commit is contained in:
Tim Shannon 2016-04-18 19:45:16 +00:00
parent 5f26454adf
commit e0bc90e954
2 changed files with 108 additions and 22 deletions

View File

@ -68,7 +68,29 @@
font-weight: bold; font-weight: bold;
font-size: 2em; font-size: 2em;
} }
.pull-left {
float: left;
}
.pull-right {
float: right;
}
.timestamp {
font-size: .75em;
color: #777;
margin-left: 10px;
}
.log {
margin-left: 15px;
margin-right: 15px;
}
.log > pre {
margin-left: 15px;
}
</style> </style>
</head> </head>
<body> <body>
@ -102,12 +124,12 @@
<a href="/project/{{project.id}}/{{version}}" class="pure-menu-link">{{version}}</a> <a href="/project/{{project.id}}/{{version}}" class="pure-menu-link">{{version}}</a>
</li> </li>
{{/if}} {{/if}}
{{#if project && version && stage}} {{#if project && version && currentStage}}
<li class="pure-menu-item"> <li class="pure-menu-item">
<span class="breadcrumb-separator">/</span> <span class="breadcrumb-separator">/</span>
</li> </li>
<li class="pure-menu-item"> <li class="pure-menu-item">
<a href="/project/{{project.id}}/{{version}}/{{stage}}" class="pure-menu-link">{{stage}}</a> <a href="/project/{{project.id}}/{{version}}/{{currentStage}}" class="pure-menu-link">{{currentStage}}</a>
</li> </li>
{{/if}} {{/if}}
</ul> </ul>
@ -116,10 +138,8 @@
{{>projects}} {{>projects}}
{{elseif !version}} {{elseif !version}}
{{>project}} {{>project}}
{{elseif !stage}}
{{>version}}
{{else}} {{else}}
{{>stage}} {{>version}}
{{/if}} {{/if}}
</div> </div>
</div> </div>
@ -141,7 +161,7 @@
</thead> </thead>
<tbody> <tbody>
{{#projects:i}} {{#projects:i}}
<tr> <tr title="{{formatDate(.lastLog.when)}}">
<td><a href="/project/{{.id}}/">{{.name}}</a></td> <td><a href="/project/{{.id}}/">{{.name}}</a></td>
<td>{{.status}}</td> <td>{{.status}}</td>
<td>{{.stage}}</td> <td>{{.stage}}</td>
@ -149,7 +169,11 @@
<a href="/project/{{.id}}/{{.releaseVersion}}">{{.releaseVersion}}</a> <a href="/project/{{.id}}/{{.releaseVersion}}">{{.releaseVersion}}</a>
</td> </td>
<td> <td>
<a href="/release/{{.id}}?file">Download</a> {{#if releases[.id]}}
<a href="/release/{{.id}}?file">{{releases[id].fileName}}</a>
{{else}}
No release file available
{{/if}}
</td> </td>
<td> <td>
<a href="/project/{{.id}}/{{.lastLog.version}}">{{.lastLog.version}}</a> <a href="/project/{{.id}}/{{.lastLog.version}}">{{.lastLog.version}}</a>
@ -175,15 +199,15 @@
</thead> </thead>
<tbody> <tbody>
{{#project.versions:i}} {{#project.versions:i}}
<tr> <tr title="{{formatDate(.when)}}">
<td> <td>
<a href="/project/{{project.id}}/{{.version}}">{{.version}}</a> <a href="/project/{{project.id}}/{{.version}}">{{.version}}</a>
</td> </td>
<td>{{.stage}}</td> <td>{{.stage}}</td>
<td title="{{.log}}">{{#if .log}}{{.log.substring(0,100) + " ..."}}{{/if}}</td> <td title="{{.log}}">{{#if .log}}{{.log.substring(0,100) + " ..."}}{{/if}}</td>
<td> <td>
{{#if .stage == "released"}} {{#if releases[project.id + .version]}}
<a href="/release/{{project.id}}/{{.version}}?file">Download</a> <a href="/release/{{project.id}}/{{.version}}?file">{{releases[project.id + .version].fileName}}</a>
{{/if}} {{/if}}
</td> </td>
</tr> </tr>
@ -195,13 +219,41 @@
{{/partial}} {{/partial}}
{{#partial version}} {{#partial version}}
<hr>
{{#if releases[project.id + .version]}}
<a href="/release/{{project.id}}/{{.version}}?file" class="pull-right pure-button pure-button-primary">Download Release</a>
{{/if}}
<div class="pure-menu pure-menu-horizontal">
<ul class="pure-menu-list">
<li class="pure-menu-item {{#if !currentStage}}pure-menu-selected{{/if}}">
<a href="/project/{{project.id}}/{{.version}}/" class="pure-menu-link">All</a>
</li>
{{#stages:i}}
<li class="pure-menu-item {{#if currentStage && currentStage == .stage}}pure-menu-selected{{/if}}">
<a href="/project/{{project.id}}/{{version}}/{{.stage}}" class="pure-menu-link">{{.stage}}</a>
</li>
{{/stages}}
</ul>
</div>
<hr>
<div class="log">
{{#if currentStage}}
<h3>{{currentStage}}<small class="timestamp">{{formatDate(logs.when)}}</small></h3>
<pre><samp>
{{logs.log}}
</samp></pre>
{{else}}
{{#stages:i}}
<h3>{{.stage}}<small class="timestamp">{{formatDate(.when)}}</small></h3>
<pre><samp>
{{.log}}
</samp></pre>
{{/stages}}
{{/if}}
</div>
{{/partial}} {{/partial}}
{{#partial stage}}
{{/partial}}
</script> </script>
<script src="/js/ractive.min.js"></script> <script src="/js/ractive.min.js"></script>
<script src="/js/index.js"></script> <script src="/js/index.js"></script>

View File

@ -15,10 +15,13 @@ Ractive.DEBUG = false;
return { return {
project: null, project: null,
version: null, version: null,
stages: null, stages: null,
stage: null, currentStage: null,
logs: null,
projects: [], projects: [],
error: null, error: null,
formatDate: formatDate,
releases: {},
}; };
}, },
}); });
@ -40,13 +43,13 @@ Ractive.DEBUG = false;
if (paths[1] == "project") { if (paths[1] == "project") {
if (paths[2]) { if (paths[2]) {
getProject(paths[2]);
if (paths[3]) { if (paths[3]) {
getVersion(paths[2], paths[3]);
if (paths[4]) { if (paths[4]) {
getStage(paths[2], paths[3], paths[4]); getStage(paths[2], paths[3], paths[4]);
} }
getVersion(paths[2], paths[3]);
} }
getProject(paths[2]);
} }
getProjects(); getProjects();
return; return;
@ -61,8 +64,8 @@ Ractive.DEBUG = false;
function(result) { function(result) {
for (var i = 0; i < result.data.length; i++) { for (var i = 0; i < result.data.length; i++) {
setStatus(result.data[i]); setStatus(result.data[i]);
hasRelease(result.data[i].id, "");
} }
r.set("projects", result.data); r.set("projects", result.data);
}, },
function(result) { function(result) {
@ -74,6 +77,11 @@ Ractive.DEBUG = false;
get("/log/" + id, get("/log/" + id,
function(result) { function(result) {
r.set("project", result.data); r.set("project", result.data);
if (result.data.versions) {
for (var i = 0; i < result.data.versions.length; i++) {
hasRelease(result.data.id, result.data.versions[i].version);
}
}
}, },
function(result) { function(result) {
r.set("error", err(result).message); r.set("error", err(result).message);
@ -81,9 +89,9 @@ Ractive.DEBUG = false;
} }
function getVersion(id, version) { function getVersion(id, version) {
r.set("version", version);
get("/log/" + id + "/" + version, get("/log/" + id + "/" + version,
function(result) { function(result) {
r.set("version", version);
r.set("stages", result.data); r.set("stages", result.data);
}, },
function(result) { function(result) {
@ -94,13 +102,27 @@ Ractive.DEBUG = false;
function getStage(id, version, stage) { function getStage(id, version, stage) {
get("/log/" + id + "/" + version + "/" + stage, get("/log/" + id + "/" + version + "/" + stage,
function(result) { function(result) {
r.set("stage", result.data); r.set("logs", result.data);
r.set("currentStage", stage);
}, },
function(result) { function(result) {
r.set("error", err(result).message); r.set("error", err(result).message);
}); });
} }
function hasRelease(id, version) {
/*/release/<project-id>/<version>*/
get("/release/" + id + "/" + version,
function(result) {
r.set("releases." + id + version, result.data);
},
function(result) {
r.set("releases." + id + version, undefined);
});
}
function setStatus(project) { function setStatus(project) {
//statuses //statuses
if (project.lastLog.version.trim() == project.releaseVersion.trim()) { if (project.lastLog.version.trim() == project.releaseVersion.trim()) {
@ -165,11 +187,23 @@ function get(url, success, error) {
function err(response) { function err(response) {
"use strict"; "use strict";
var error = { var error = {
message: "An error occurred and has been logged", message: "An error occurred",
}; };
if (typeof response === "string") { if (typeof response === "string") {
error.message = response; error.message = response;
} else {
error.message = JSON.parse(response.responseText).message;
} }
return error; return error;
} }
function formatDate(strDate) {
"use strict";
var date = new Date(strDate);
if (!date) {
return "";
}
return date.toLocaleDateString() + " at " + date.toLocaleTimeString();
}