-
Notifications
You must be signed in to change notification settings - Fork 569
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
//// START GITLAB | ||
togglbutton.render( | ||
'.issue-details .detail-page-description:not(.toggl)', | ||
{ observe: !0 }, | ||
function (t) { | ||
const n = [ | ||
[a()] | ||
.filter(Boolean) | ||
.map(function (r) { | ||
return '#' + r; | ||
}) | ||
.join(''), | ||
i(t), | ||
] | ||
.filter(Boolean) | ||
.join(' '); | ||
o($('.detail-page-header-actions'), n, !0), o($('.time-tracker'), n); | ||
} | ||
); | ||
togglbutton.render( | ||
'.merge-request > .detail-page-header:not(.toggl)', | ||
{ observe: !0 }, | ||
function (t) { | ||
const n = [ | ||
[a()] | ||
.filter(Boolean) | ||
.map(function (r) { | ||
return 'MR' + r + '::'; | ||
}) | ||
.join(''), | ||
i(t), | ||
] | ||
.filter(Boolean) | ||
.join(' '); | ||
o($('.detail-page-header-actions'), n, !0), o($('.time-tracker'), n); | ||
} | ||
); | ||
function o(t, e, n = !1) { | ||
const r = togglbutton.createTimerLink({ | ||
className: 'gitlab', | ||
description: e, | ||
tags: l, | ||
taskId: (o, i) => { | ||
return extractTaskId(o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(o, i); | ||
}, | ||
}); | ||
n ? t.parentElement.insertBefore(r, t) : t.parentElement.appendChild(r, t); | ||
} | ||
function i(t) { | ||
const e = t.querySelector('.title'); | ||
return e ? e.textContent.trim() : ''; | ||
} | ||
function a() { | ||
const t = window.location.pathname, | ||
e = /-\/(issues|merge_requests)\/(?<id>\d+)/; | ||
return (e.test(t) ? t.match(e) : { groups: { id: '' } }).groups.id; | ||
} | ||
function s() { | ||
const t = | ||
$('.title .project-item-select-holder') || | ||
$('.breadcrumbs-list li:nth-last-child(3) .breadcrumb-item-text'); | ||
return t ? t.textContent.trim() : ''; | ||
} | ||
function l() { | ||
const t = document.querySelectorAll('div.labels span[data-qa-label-name]'); | ||
if (!t) return []; | ||
const e = []; | ||
for (const n of Object.values(t)) { | ||
const r = n.getAttribute('data-qa-label-name'); | ||
e.push(r); | ||
} | ||
return e; | ||
} | ||
|
||
////END GITLAB | ||
|
||
////START HELPER | ||
const ExtractN4GitlabTogglTaskId = () => { | ||
debugger; | ||
let togglTaskId = null; | ||
let tags = l(); | ||
const GITLAB_LABEL_REGEX = /togg(e|)l(::|:)/gim; | ||
const REMOVE_TRALING_LABEL_DESCRIPTION = / .*/; | ||
|
||
debugger; | ||
if (Array.isArray(tags)) { | ||
tags.forEach((element) => { | ||
if (element.match(GITLAB_LABEL_REGEX)) { | ||
togglTaskId = element | ||
.replace(GITLAB_LABEL_REGEX, '') | ||
.toUpperCase() | ||
.replace(REMOVE_TRALING_LABEL_DESCRIPTION, ''); | ||
return; | ||
} | ||
}); | ||
} | ||
return togglTaskId; | ||
}; | ||
|
||
function extractTaskId(projects, tasks) { | ||
debugger; | ||
let n4TogglTask = ExtractN4GitlabTogglTaskId(); | ||
if (n4TogglTask === null) { | ||
return {}; | ||
} | ||
|
||
const n = Object.keys(tasks).filter((o) => | ||
tasks[o].name.startsWith(n4TogglTask) | ||
), | ||
s = n.length > 0 ? tasks[n[0]].id : {}; | ||
return s; | ||
} | ||
|
||
function extractTaskProjectId(n4TogglTask, projects, tasks) { | ||
if (n4TogglTask === null) { | ||
return null; | ||
} | ||
|
||
const n = Object.keys(tasks).filter((o) => | ||
tasks[o].name.startsWith(n4TogglTask) | ||
), | ||
s = n.length > 0 ? tasks[n[0]].project_id : null; | ||
console.log(s); | ||
return s; | ||
} | ||
|
||
function extractProjectName(projects, tasks) { | ||
debugger; | ||
let n4TogglTask = ExtractN4GitlabTogglTaskId(); | ||
if (n4TogglTask === null) { | ||
return null; | ||
} | ||
|
||
let projectID = extractTaskProjectId(n4TogglTask, projects, tasks); | ||
const n = Object.keys(projects).filter((o) => projects[o].id === projectID), | ||
s = n.length > 0 ? projects[n[0]].name : null; | ||
console.log(s); | ||
return s; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
/// START JIRA | ||
|
||
togglbutton.render( | ||
'#ghx-detail-view [spacing] h1:not(.toggl)', | ||
{ observe: !0 }, | ||
function () { | ||
debugger; | ||
({}).DEBUG && console.info('\u{1F3C3} "Jira 2017 sidebar" rendering'); | ||
const n = $('#ghx-detail-view'), | ||
t = createTag('div', 'jira-ghx-toggl-button'), | ||
i = $('[spacing] h1', n), | ||
e = $('[spacing] a', n), | ||
o = $('.bgdPDV'); | ||
let r = i.textContent; | ||
e !== null && (r = e.textContent + ' ' + r); | ||
const a = togglbutton.createTimerLink({ | ||
className: 'jira2017', | ||
description: r, | ||
buttonType: 'minimal', | ||
taskId: (o, i) => { | ||
return extractTaskId(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
}); | ||
t.appendChild(a), e.parentNode.appendChild(t); | ||
} | ||
); | ||
|
||
togglbutton.render('#title-heading:not(.toggl)', { observe: !0 }, function (n) { | ||
const i = $('[id="title-text"]', n).textContent.trim(), | ||
e = togglbutton.createTimerLink({ | ||
className: 'confluence', | ||
description: i, | ||
taskId: (o, i) => { | ||
return extractTaskId(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
}); | ||
$('#title-text').appendChild(e); | ||
}); | ||
|
||
//JIRA Issue View | ||
togglbutton.render( | ||
'.issue-header-content:not(.toggl)', | ||
{ observe: !0 }, | ||
function (n) { | ||
debugger; | ||
({}).DEBUG && console.info('\u{1F3C3} "Jira 2017 issue page" rendering'); | ||
const t = $('#key-val', n), | ||
i = $('#summary-val', n) || ''; | ||
let e = $('.bgdPDV'), | ||
o; | ||
i && (o = i.textContent.trim()), | ||
t !== null && (o && (o = ' ' + o), (o = t.textContent + o)), | ||
e === null && | ||
(e = $( | ||
'[data-test-id="navigation-apps.project-switcher-v2"] button > div:nth-child(2) > div' | ||
)), | ||
e === null && (e = $('#project-name-val')); | ||
|
||
const r = togglbutton.createTimerLink({ | ||
className: 'jira2017', | ||
description: o, | ||
taskId: (o, i) => { | ||
return extractTaskId(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
}); | ||
r.style.marginLeft = '8px'; | ||
const a = | ||
($('.issue-link') || {}).parentElement || | ||
($('.aui-nav li') || {}).lastElementChild; | ||
a && a.appendChild(r); | ||
} | ||
); | ||
|
||
//JIRA Board Detail | ||
togglbutton.render( | ||
'#ghx-detail-issue:not(.toggl)', | ||
{ observe: !0 }, | ||
function (n) { | ||
debugger; | ||
const t = createTag('div', 'ghx-toggl-button'), | ||
i = $('[data-field-id="summary"]', n), | ||
e = $('.ghx-fieldname-issuekey a'), | ||
o = $('.ghx-project', n); | ||
let r = i.textContent; | ||
e !== null && (r = e.textContent + ' ' + r); | ||
const a = togglbutton.createTimerLink({ | ||
className: 'jira', | ||
description: r, | ||
taskId: (o, i) => { | ||
return extractTaskId(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
}); | ||
t.appendChild(a), $('#ghx-detail-head').appendChild(t); | ||
} | ||
); | ||
|
||
// JIRA Issue List Issue View | ||
togglbutton.render( | ||
'.issue-header-content:not(.toggl)', | ||
{ observe: !0 }, | ||
function (n) { | ||
debugger; | ||
let t; | ||
const i = $('#key-val', n), | ||
e = $('#summary-val', n) || '', | ||
o = $('#project-name-val', n); | ||
e && (t = e.textContent), | ||
i !== null && (t && (t = ' ' + t), (t = i.textContent + t)); | ||
const r = togglbutton.createTimerLink({ | ||
className: 'jira', | ||
description: t, | ||
taskId: (o, i) => { | ||
return extractTaskId(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
projectName: (o, i) => { | ||
return extractProjectName(ExtractN4JiraTogglTaskId(), o, i); | ||
}, | ||
}), | ||
a = createTag('ul', 'toolbar-group'), | ||
s = createTag('li', 'toolbar-item'); | ||
s.appendChild(r), a.appendChild(s), $('.toolbar-split-left').appendChild(a); | ||
} | ||
); | ||
//// END JIRA | ||
|
||
////START HELPER | ||
const ExtractN4JiraTogglTaskId = () => { | ||
let e = ''; | ||
const t = document.querySelector('#customfield_10206-val'); | ||
let ret = | ||
(t && (e && (e += ' '), (e += t.textContent.trim())), | ||
e.split('-')[0].trim()); | ||
return ret.length > 0 ? ret : null; | ||
}; | ||
|
||
function extractTaskId(n4TogglTask, projects, tasks) { | ||
if (n4TogglTask === null) { | ||
return {}; | ||
} | ||
const n = Object.keys(tasks).filter((o) => | ||
tasks[o].name.startsWith(n4TogglTask) | ||
), | ||
s = n.length > 0 ? tasks[n[0]].id : {}; | ||
return s; | ||
} | ||
|
||
function extractTaskProjectId(n4TogglTask, projects, tasks) { | ||
debugger; | ||
if (n4TogglTask === null) { | ||
return null; | ||
} | ||
const n = Object.keys(tasks).filter((o) => | ||
tasks[o].name.startsWith(n4TogglTask) | ||
), | ||
s = n.length > 0 ? tasks[n[0]].project_id : null; | ||
console.log(s); | ||
return s; | ||
} | ||
|
||
function extractProjectName(n4TogglTask, projects, tasks) { | ||
if (n4TogglTask === null) { | ||
return null; | ||
} | ||
let projectID = extractTaskProjectId(n4TogglTask, projects, tasks); | ||
const n = Object.keys(projects).filter((o) => projects[o].id === projectID), | ||
s = n.length > 0 ? projects[n[0]].name : null; | ||
console.log(s); | ||
return s; | ||
} | ||
|
||
////END HELPER |
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