diff --git a/ui/src/visualizations/File-Evolution/sagas/getBranches.js b/ui/src/visualizations/File-Evolution/sagas/getBranches.js new file mode 100644 index 00000000..12c0ae14 --- /dev/null +++ b/ui/src/visualizations/File-Evolution/sagas/getBranches.js @@ -0,0 +1,35 @@ +'use strict'; + +import { traversePages, graphQl } from '../../../utils'; + +/** + * Get branches from the database. + * @returns {*} + */ +export default function getBranches() { + const branchList = []; + + return traversePages(getBranchPage(), branch => { + branchList.push(branch); + }).then(function() { + return branchList; + }); +} + +const getBranchPage = until => (page, perPage) => { + return graphQl + .query( + `query ($page: Int, $perPage: Int) { + branches(page: $page, perPage: $perPage, sort: "ASC") { + count + data{ + id + branch + active + } + } + }`, + { page, perPage } + ) + .then(resp => resp.branches); +}; diff --git a/ui/src/visualizations/File-Evolution/sagas/getCommitData.js b/ui/src/visualizations/File-Evolution/sagas/getCommitData.js new file mode 100644 index 00000000..99c5a33a --- /dev/null +++ b/ui/src/visualizations/File-Evolution/sagas/getCommitData.js @@ -0,0 +1,42 @@ +'use strict'; + +import { traversePages, graphQl } from '../../../utils'; + +/** + * Get commit data from the database. + * @returns {*} + */ +export default function getCommitData() { + const commitList = []; + + return traversePages(getCommitsPage(), commit => { + commitList.push(commit); + }).then(function() { + return commitList; + }); +} + +const getCommitsPage = until => (page, perPage) => { + return graphQl + .query( + `query($page: Int, $perPage: Int) { + commits(page: $page, perPage: $perPage, sort: "ASC" ) { + count + data { + sha + date + message + messageHeader + signature + webUrl + stats { + additions + deletions + } + } + } + }`, + { page, perPage, until } + ) + .then(resp => resp.commits); +}; diff --git a/ui/src/visualizations/File-Evolution/sagas/getCommiters.js b/ui/src/visualizations/File-Evolution/sagas/getCommiters.js new file mode 100644 index 00000000..b88cecd0 --- /dev/null +++ b/ui/src/visualizations/File-Evolution/sagas/getCommiters.js @@ -0,0 +1,31 @@ +'use strict'; + +import { traversePages, graphQl } from '../../../utils'; + +/** + * @returns {*} (see below) + */ +export default function getCommiters() { + const committers = []; + + return traversePages(getCommittersPage(), stakeholders => { + committers.push(stakeholders); + }).then(function() { + return committers; + }); +} + +const getCommittersPage = until => (page, perPage) => { + return graphQl + .query( + `query ($page: Int, $perPage: Int) { + stakeholders(page: $page, perPage: $perPage) { + data{ + gitSignature, + } + } +}`, + { page, perPage, until } + ) + .then(resp => resp.stakeholders); +}; diff --git a/ui/src/visualizations/File-Evolution/sagas/index.js b/ui/src/visualizations/File-Evolution/sagas/index.js new file mode 100644 index 00000000..8dc83439 --- /dev/null +++ b/ui/src/visualizations/File-Evolution/sagas/index.js @@ -0,0 +1,111 @@ +'use strict'; + +import Promise from 'bluebird'; +import { createAction } from 'redux-actions'; +import { throttle, fork, takeEvery, select } from 'redux-saga/effects'; + +import { fetchFactory, timestampedActionFactory, mapSaga } from '../../../sagas/utils.js'; +import getCommitData from './getCommitData.js'; +import getBranches from './getBranches.js'; +import getCommiters from './getCommiters.js'; + +export const setCommitBoxHeight = createAction('SET_COMMIT_BOX_HEIGHT'); +export const setCommitBoxWidth = createAction('SET_COMMIT_BOX_WIDTH'); +export const setCommitBoxColor = createAction('SET_COMMIT_BOX_COLOR'); + +export const setSelectedAuthors = createAction('SET_SELECTED_AUTHORS'); +export const setSelectedBranches = createAction('SET_SELECTED_BRANCHES'); + +export const setShowCommitDate = createAction('SET_SHOW_COMMIT_DATE'); +export const setShowCommitMessage = createAction('SET_SHOW_COMMIT_MESSAGE'); +export const setShowCommitAuthor = createAction('SET_SHOW_COMMIT_AUTHOR'); + +export const requestFileEvolutionData = createAction('REQUEST_FILE_EVOLUTION_DATA'); +export const receiveFileEvolutionData = timestampedActionFactory('RECEIVE_FILE_EVOLUTION_DATA'); +export const receiveFileEvolutionDataError = createAction('RECEIVE_FILE_EVOLUTION_DATA_ERROR'); + +export const requestRefresh = createAction('REQUEST_REFRESH'); +const refresh = createAction('REFRESH'); + +export default function*() { + // fetch data once on entry + yield* fetchFileEvolutionData(); + + yield fork(watchRefreshRequests); + yield fork(watchMessages); + + // keep looking for viewport changes to re-fetch + yield fork(watchRefresh); + yield fork(watchToggleHelp); +} + +function* watchRefreshRequests() { + yield throttle(2000, 'REQUEST_REFRESH', mapSaga(refresh)); +} + +function* watchMessages() { + yield takeEvery('message', mapSaga(requestRefresh)); +} + +function* watchToggleHelp() { + yield takeEvery('TOGGLE_HELP', mapSaga(refresh)); +} + +function* watchRefresh() { + yield takeEvery('REFRESH', fetchFileEvolutionData); +} + +/** + * Fetch data for FILE EVOLUTION, this still includes old functions that were copied over. + */ +export const fetchFileEvolutionData = fetchFactory( + function*() { + //const commiters = yield getCommiters(); + return yield Promise.join(getCommitData(), getBranches(), getCommiters()) + .spread((commits, branches, commiters) => { + const authorsColorPalette = getAuthorColorPalette(commiters); + const branchesColorPalette = getBranchesColorPalette(branches); + return { + commits, + branches, + commiters, + authorsColorPalette, + branchesColorPalette + }; + }) + .catch(function(e) { + console.error(e.stack); + throw e; + }); + }, + requestFileEvolutionData, + receiveFileEvolutionData, + receiveFileEvolutionDataError +); + +function getAuthorColorPalette(commiters) { + //TODO Color??? + const colorPalette = {}; + for (const i in commiters) { + let randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16); + while (randomColor.length !== 7) { + randomColor = randomColor + '0'; + } + colorPalette[commiters[i].gitSignature] = randomColor; + } + return colorPalette; +} + +function getBranchesColorPalette(branches) { + //TODO Color??? + const colorPalette = {}; + for (const i in branches) { + let randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16); + while (randomColor.length !== 7) { + randomColor = randomColor + '0'; + } + colorPalette[branches[i].branch] = randomColor; + } + console.log(colorPalette); + return colorPalette; +}