This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/projects/ProjectItem.js

99 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-02-21 12:05:14 +00:00
import React from 'react-native';
2016-02-23 23:12:32 +00:00
import GlobalStyles from '../../settings/styles';
import { getProjectRecentBuilds } from '../../api/CircleCI';
2016-02-21 12:05:14 +00:00
2016-02-23 23:12:32 +00:00
const {
2016-02-21 12:05:14 +00:00
View,
Text,
2016-02-23 23:12:32 +00:00
StyleSheet
2016-02-21 12:05:14 +00:00
} = React;
2016-02-23 23:12:32 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
height: 70,
alignItems: 'stretch',
backgroundColor: GlobalStyles.get('CIRCLE_ITEM_BG'),
borderBottomColor: GlobalStyles.get('CIRCLE_ITEM_BORDER'),
2016-02-24 18:00:50 +00:00
borderBottomWidth: 2,
marginVertical: 2.5,
flexDirection: 'row',
2016-02-23 23:12:32 +00:00
},
2016-02-24 18:00:50 +00:00
repoCell: {
2016-02-23 23:12:32 +00:00
paddingHorizontal: 4,
2016-02-24 18:00:50 +00:00
paddingVertical: 3,
flex: 0.74
2016-02-23 23:12:32 +00:00
},
2016-02-24 18:00:50 +00:00
buildCell: {
flex: 0.35
},
colourPanel: {
flex: 0.02
2016-02-23 23:12:32 +00:00
},
repoName: {
2016-02-24 18:00:50 +00:00
fontSize: 15,
2016-02-23 23:12:32 +00:00
fontWeight: '500'
2016-02-24 18:00:50 +00:00
},
details: {
fontSize: 13,
fontWeight: '300'
2016-02-23 23:12:32 +00:00
}
});
2016-02-21 12:05:14 +00:00
export default class ProjectItem extends React.Component {
2016-02-23 23:12:32 +00:00
constructor() {
super();
this.state = {
recentBuild: false
};
this._displayMoreInfo = this._displayMoreInfo.bind(this);
}
componentDidMount() {
getProjectRecentBuilds(this.props.project.username, this.props.project.reponame).then(function (recentBuild) {
this.setState({ recentBuild: recentBuild[0] });
}.bind(this));
}
_displayMoreInfo(mostRecentBuild) {
let seconds = Math.floor(mostRecentBuild.build_time_millis / 1000);
const minutes = Math.floor(seconds / 60);
seconds = seconds - (minutes * 60);
2016-02-24 18:00:50 +00:00
const buildTime = minutes + ':' + seconds;
const commit = mostRecentBuild.all_commit_details[0];
2016-02-23 23:12:32 +00:00
return (
2016-02-24 18:00:50 +00:00
<View>
<Text style={styles.details} >T: { buildTime }</Text>
<Text style={styles.details} >B: { commit.branch }</Text>
<Text style={styles.details} >#{ mostRecentBuild.build_num }</Text>
</View>
2016-02-23 23:12:32 +00:00
);
}
2016-02-21 12:05:14 +00:00
render() {
2016-02-23 23:12:32 +00:00
console.log(this.props.userDetails);
const project = this.props.project;
const mostRecentBuild = this.state.recentBuild;
2016-02-24 18:10:16 +00:00
const statusColour = mostRecentBuild.failed ?
GlobalStyles.get('CIRCLE_TEST_FAIL') :
GlobalStyles.get('CIRCLE_TEST_PASS');
2016-02-23 23:12:32 +00:00
let username;
if (this.props.userDetails && this.props.userDetails.login !== project.username) {
2016-02-24 18:00:50 +00:00
username = project.username + '/';
2016-02-23 23:12:32 +00:00
}
const buildDetails = mostRecentBuild ? this._displayMoreInfo(mostRecentBuild) : null;
2016-02-21 12:05:14 +00:00
return (
2016-02-23 23:12:32 +00:00
<View style={styles.container}>
2016-02-24 18:00:50 +00:00
<View style={styles.repoCell}>
<Text style={styles.repoName}>{username}{project.reponame}</Text>
2016-02-23 23:12:32 +00:00
</View>
2016-02-24 18:00:50 +00:00
<View style={styles.buildCell}>
2016-02-23 23:12:32 +00:00
{ buildDetails }
</View>
2016-02-24 18:00:50 +00:00
<View style={[styles.colourPanel, {backgroundColor: statusColour}]} />
2016-02-23 23:12:32 +00:00
</View>
2016-02-21 12:05:14 +00:00
);
}
};