This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
GitHut.js
120 lines (112 loc) · 3.58 KB
/
GitHut.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* @flow */
/* global _ angular */
/* eslint
fp/no-class:0,
fp/no-this:0,
fp/no-mutation:0,
class-methods-use-this:0,
react/prefer-stateless-function:0,
max-len:0,
flowtype/require-parameter-type:0,
flowtype/require-return-type:0,
no-param-reassign:0,
no-useless-escape:0,
no-unused-vars:1,
no-else-return:0,
react/prop-types:1,
*/
import React from 'react';
import JSURL from 'jsurl';
import { compose } from 'recompose';
import withRouter from '@ncigdc/utils/withRouter';
// Append d3-tip for githut. Appending here to avoid issues in load order.
const d3TipUrl = 'https://cdnjs.cloudflare.com/ajax/libs/d3-tip/0.7.1/d3-tip.min.js';
const existingScript = document.querySelector(`script[src="${d3TipUrl}"`);
if (!existingScript) {
const script = document.createElement('script');
script.src = d3TipUrl;
document.body.appendChild(script);
}
export default
compose(withRouter)(
class GitHut extends React.Component {
componentDidMount() {
const self = this;
angular
.module('legacyAngularWrapper', ['ngApp'])
.config(['$locationProvider', 'RestangularProvider', ($locationProvider, RestangularProvider) => {
$locationProvider.html5Mode(false);
RestangularProvider.setBaseUrl(API);
// Previous API treated "from=0" to be the same as "from=1", the current API doesn't.
RestangularProvider.addFullRequestInterceptor((element, operation, what, url, headers, query) => ({
params: Object.assign({}, query, { from: query.from === 1 ? 0 : query.from }),
}));
}])
.run(['$browser', 'LocationService', '$state', ($browser, LocationService, $state) => {
// angular dirty checks the browser url and messes with routing in other pages
let pendingLocation = null;
$browser.url = function (url, replace, state) {
if (url) {
pendingLocation = url;
return $browser;
} else {
return pendingLocation || location.href.replace(/%27/g, "'");
}
};
$state.go = this.handleAngularRouterRequestGo;
LocationService.filters = () => this.props.params.filters;
}])
.directive('githut', () => ({
controller: 'ProjectsController as prsc',
link(scope, element, attrs, controller) {
controller.ProjectsState.tabs.graph.active = true;
self.angularController = controller;
},
template: `
<git-hut
data-ng-if="prsc.githutData"
data="prsc.githutData"
config="prsc.githutConfig"
></git-hut>
`,
}));
angular.bootstrap(this.container, ['legacyAngularWrapper']);
}
componentDidUpdate() {
if (this.angularController) {
this.angularController.refresh();
}
}
handleAngularRouterRequestGo = (state, params, options) => {
const stateMap = {
'search.participants': {
pathname: '/repository',
children: 'repository',
query: {
searchTableTab: 'cases',
filters: JSURL.stringify(JSON.parse(params.filters || null)),
},
},
'search.files': {
pathname: '/repository',
children: 'repository',
query: {
searchTableTab: 'files',
filters: JSURL.stringify(JSON.parse(params.filters || null)),
},
},
project: {
pathname: `/projects/${params.projectId}`,
},
};
this.props.push(stateMap[state]);
}
render() {
return (
<div
ref={c => { this.container = c; }}
dangerouslySetInnerHTML={{ __html: '<githut></githut>' }}
/>
);
}
})