Created
November 27, 2015 21:44
-
-
Save Nepoxx/e09b704a25ba8099811f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inject, LogManager} from 'aurelia-framework'; | |
import {HttpClient} from 'aurelia-fetch-client'; | |
import _ from 'lodash'; | |
import 'fetch'; | |
const refreshRateInSeconds = 30; | |
@inject(HttpClient, LogManager) | |
export class Users { | |
heading = 'Current Builds'; | |
selectedProjectName = ''; | |
builds = []; | |
baseurl = 'http://192.168.4.9:2001'; | |
authHeader; | |
constructor(http, logManager) { | |
this.logger = logManager.getLogger('builds'); | |
this.authHeader = 'Bearer ' + window.localStorage.getItem('redist_token'); | |
http.configure(config => { | |
config | |
.useStandardConfiguration() | |
.withBaseUrl(this.baseurl); | |
}); | |
this.http = http; | |
} | |
activate(pathParams) { | |
this.logger.debug('Activate'); | |
this.fetchUrl = '/build'; | |
this.builds = []; | |
this.builds.push({pn: 'test'}); | |
if (pathParams && pathParams.projectName) { | |
this.fetchUrl = `/project/${pathParams.projectName}/builds`; | |
this.selectedProjectName = pathParams.projectName; | |
this.builds.push({pn: 'pathparam'}) | |
} | |
return this.getBuilds(); | |
} | |
deactivate() { | |
this.logger.debug('Deactivate'); | |
this.builds.length = 0; | |
this.selectedProjectName = ''; | |
clearInterval(this.autoRefreshFct); | |
} | |
getBuilds() { | |
return this.http.fetch(this.fetchUrl, { | |
headers: { | |
'Authorization': this.authHeader | |
} | |
}) | |
.then(response => response.json()) | |
.then(builds => { | |
let sortedBuilds = _.sortByOrder(builds, ['ts'], ['desc']); | |
_.forEach(sortedBuilds, b => { | |
b.ts = new Date(b.ts); | |
this.builds.push(b); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment