Created
July 7, 2017 16:34
-
-
Save Michaela-Davis/d4447421a18198f99ff645898e2787c9 to your computer and use it in GitHub Desktop.
Dashboard bits - dashboard/app/services/getProfilePicture.service.js, dashboard/app/jobs/index.js
This file contains 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
'use strict'; | |
//controller import stuff | |
const pkg = require.main.require('../package.json'); | |
const mongoose = require('mongoose'); | |
const superagent = require('superagent'); | |
const Promise = require('bluebird'); | |
const _ = require('lodash'); | |
module.exports = getProfilePictures; | |
function getProfilePictures() { | |
const MergeRequest = mongoose.model('MergeRequest'); | |
console.log('getProfilePictures function has been called to run...'); | |
let users = []; | |
superagent.get(`https://git.soliddigital.com/api/v3/users?per_page=200&active=true`) | |
.set('PRIVATE-TOKEN', 'w2aqHLt7oLUgoozHSUMz') | |
.then(usersResponse => { | |
let users = usersResponse.body; | |
let vals = users.map(user => { | |
return { | |
name: user.name, | |
avatar: user.avatar_url | |
} | |
}); | |
Promise.each(_.range(0, vals.length), m => { | |
return MergeRequest.update({ | |
//look into database for users in DB and if found, update/add their Profile Picture | |
authorName: vals[m].name | |
}, { | |
avatar: vals[m].avatar | |
}, { | |
multi: true | |
}) | |
.then(() => { | |
console.log('updating profile pictures', vals[m].avatar); | |
}) | |
.catch(e => { | |
console.log('e', e) | |
}); | |
}); | |
}); | |
}; |
This file contains 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
'use strict'; | |
const Agenda = require('agenda'); | |
const configs = require.main.require('./configs'); | |
// Export a method so expressively can auto call it | |
module.exports = start; | |
function start(services) { | |
let agenda = new Agenda({ | |
name : `DevopsDahsboard-${process.pid}`, | |
db : { | |
address: `${configs.grasshopper.db.base}/agenda` | |
} | |
}); | |
agenda.define('sync pingdom uptimes', (job, done) => { | |
console.log('*** syncing uptimes start ***', new Date); | |
services.pingdomSyncer() | |
.catch(e => { console.log('pingdom sync error:', e); }) | |
.finally(() => { | |
console.log('*** syncing uptimes end', new Date); | |
done(); | |
}); | |
}); | |
agenda.define('sync merge requests', (job, done) => { | |
console.log('I am running the merge request service!'); | |
services.callMergeRequests() | |
.catch(e => { console.log('sync merge requests error: ', e); }) | |
.finally(() => { | |
done(); | |
}); | |
}); | |
agenda.define('get profile pictures / avatars', (job, done) => { | |
console.log('Getting profile pictures / avatars'); | |
services.getProfilePicture() | |
.catch(e => { console.log('get profile pictures / avatars error: ', e); }) | |
.finally(() => { | |
done(); | |
}); | |
}); | |
agenda.on('ready', () => { | |
console.log('agenda is ready', new Date); | |
// use crontab format if more precision is needed 0 0 * * * * | |
agenda.every('1 day', 'sync pingdom uptimes'); | |
agenda.every('midnight', 'sync merge requests'); | |
agenda.every('12:30am', 'get profile pictures / avatars'); | |
// agenda.schedule('in 10 seconds', 'get profile pictures / avatars'); | |
// agenda.schedule('in 20 seconds', 'sync merge requests'); | |
agenda.start(); | |
}); | |
} |
This file contains 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
<script> | |
'use strict'; | |
import moment from 'moment'; | |
import Vue2Filters from 'vue2-filters'; | |
import _ from 'lodash'; | |
export default { | |
name: 'vue-user-details', | |
props: ['userList', 'mergeRequestsByUser', 'closedRequestsTotals', 'averageUsersCloseTimes'], | |
data() { | |
return { | |
message: 'Vue User Details', | |
sortedUserData: [], | |
lastSort: '', | |
sortCount: 0 | |
}; | |
}, | |
computed: { | |
userMergeRequests: function() { | |
return this.getSpecificUserValue(this.mergeRequestsByUser, this.$route.params.authorName); | |
}, | |
profilePicture: function() { | |
let profilePicture = this.getSpecificUserValue(this.mergeRequestsByUser)[0].avatar; | |
if (profilePicture) { | |
return profilePicture; | |
} else { | |
return "../../public/images/blocked.jpeg"; | |
} | |
} | |
}, | |
methods: { | |
getSpecificUserValue: function(groupDataArray) { | |
let output = []; | |
for (let i = 0; i < this.userList.length; i++) { | |
if (this.mergeRequestsByUser[i][0].authorName === this.$route.params.authorName) { | |
output.push(groupDataArray[i]); | |
} | |
} | |
return output[0]; | |
}, | |
dateFormat: function(dateValue) { | |
return moment(String(dateValue)).format('dddd, MMMM Do YYYY, hh:mm:ss a'); | |
}, | |
sortBy: function(property) { | |
if (this.lastSort === property && this.sortCount % 2 === 0) { | |
this.sortedUserData = _.sortBy(this.userMergeRequests, property); | |
this.sortCount = 1; | |
} else if (this.lastSort === property && this.sortCount % 2 != 0) { | |
this.sortedUserData = _.sortBy(this.userMergeRequests, property).reverse(); | |
this.sortCount = 0; | |
} else { | |
this.sortedUserData = _.sortBy(this.userMergeRequests, property).reverse(); | |
this.lastSort = property; | |
this.sortCount = 0; | |
} | |
return this.sortedUserData; | |
} | |
}, | |
beforeMount() { | |
this.sortBy('projectName'); | |
} | |
} | |
</script> | |
<template lang="pug"> | |
div.container | |
img.sizeAvatarPicturesOnDetail(v-bind:src="profilePicture") | |
h3#userDetailsDisplay.frescaFont {{ $route.params.authorName }} has completed {{ getSpecificUserValue(mergeRequestsByUser, $route.params.authorName).length }} merge requests to date! They have closed {{ getSpecificUserValue(closedRequestsTotals, $route.params.authorName) }} requests. On average, it takes them {{ getSpecificUserValue(averageUsersCloseTimes, $route.params.authorName) }} to close a merge request. | |
table#userDetailTable | |
tr | |
th(v-on:click="sortBy('projectName')").headingTitlePadding.tableSort Project | |
th(v-on:click="sortBy('title')").headingTitlePadding.tableSort Title | |
th(v-on:click="sortBy('description')").headingTitlePadding.tableSort Description | |
th(v-on:click="sortBy('createdDate')").headingTitlePadding.tableSort Created | |
th(v-on:click="sortBy('state')").headingTitlePadding.tableSort State | |
th(v-on:click="sortBy('closedDate')").headingTitlePadding.tableSort Merged | |
tr(v-for="userRequest in sortedUserData") | |
td | |
a(:href="userRequest.web_url") {{ userRequest.projectName | capitalize }} | |
td(v-if="!userRequest.title") | |
a(:href="userRequest.web_url") N/A | |
td(v-else) | |
a(:href="userRequest.web_url") {{ userRequest.title | capitalize }} | |
td(v-if="!userRequest.description") | |
a(:href="userRequest.web_url") N/A | |
td(v-else) | |
a(:href="userRequest.web_url") {{ userRequest.description | capitalize }} | |
td | |
a(:href="userRequest.web_url") {{ dateFormat(userRequest.createdDate) }} | |
td | |
a(:href="userRequest.web_url") {{ userRequest.state }} | |
td(v-if="userRequest.state !='opened'") | |
a(:href="userRequest.web_url") {{ dateFormat(userRequest.closedDate) }} | |
td(v-else) | |
a(:href="userRequest.web_url") N/A | |
router-link.frescaFontWhite (to='/') Back to users list | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment