-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommon.js
More file actions
89 lines (88 loc) · 2.63 KB
/
Copy pathcommon.js
File metadata and controls
89 lines (88 loc) · 2.63 KB
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
const drupalConfig = {
statusField: {
ACTIVE: "1",
FIXED: "2",
CLOSED_DUPLICATE: "3",
POSTPONED: "4",
CLOSED_WONT_FIX: "5",
CLOSED_WORKS_AS_DESIGNED: "6",
CLOSED_FIXED: "7",
NEEDS_REVIEW: "8",
NEEDS_WORK: "13",
RTBC: "14",
PATCH_TO_BE_PORTED: "15",
POSTPONED_MAINTAINER_NEEDS_MO_INFO: "16",
CLOSED_OUTDATED: "17",
CLOSED_CANNOT_REPRODUCE: "18",
},
};
const utils = {
settingDefaults: {
projects: [],
load_pages: false,
auto_tags: ["Needs tests", "Needs issue summary update", "Accessibility"],
},
getIssueListViewElement: function () {
return document.querySelector(
".view-project-issue-search-project-searchapi"
);
},
getIssueIdFromUrl: function (url) {
let parts = url.split("/");
let lastPart = parts[parts.length - 1];
parts = lastPart.split("#");
parts = parts[0].split("?");
return parts[0];
},
getStatusForId: (id) => {
return Object.keys(drupalConfig.statusField).find(
(key) => drupalConfig.statusField[key] === id
);
},
getIssueTableElement: function () {
return this.getIssueListViewElement().querySelector("table.project-issue");
},
getNidForRow: function (rowElement) {
const issueLink = rowElement.querySelector(".views-field-title a");
return utils.getIssueIdFromUrl(issueLink.getAttribute("href"));
},
gotoNode: function (nid, queryString) {
let url = `https://www.drupal.org/i/${nid}`;
if (queryString !== undefined) {
url += `?${queryString}`;
}
window.location.href = url;
},
setProject: function (project) {
this.getIssueListViewElement().setAttribute("current_project", project);
},
getProject: function () {
const viewsElement = this.getIssueListViewElement();
if (viewsElement !== null && viewsElement !== undefined) {
return viewsElement.getAttribute("current_project");
}
let url = document.URL;
url = url.replace("https://www.drupal.org/project/", "");
const parts = url.split("/");
return parts[0];
},
sleep: function (ms) {
return new Promise((resolve) =>
setTimeout(resolve, this.getRandomInt(ms - 200, ms))
);
},
getRandomInt: function (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
},
removeArrayItem: function (theArray, theItem) {
const index = theArray.indexOf(theItem);
if (index > -1) {
// only splice array when item is found
theArray.splice(index, 1); // 2nd parameter means remove one item only
}
return theArray;
},
};
export { utils };