...
 
Commits (3)
* Allow configuring label (or lack of label) - even give a list of possible labels
* Fix detection of gitlab_user_id
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
viewBox="0 0 67.733333 67.733333"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="icon.svg"
inkscape:export-filename="/home/mark/src/todolab/todolab-webextension/icons/icon_48.png"
inkscape:export-xdpi="18.000002"
inkscape:export-ydpi="18.000002">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.1484375"
inkscape:cx="-8.597252"
inkscape:cy="137.90349"
inkscape:document-units="mm"
inkscape:current-layer="g42"
showgrid="false"
units="px"
width="256px"
showguides="false"
inkscape:snap-text-baseline="false"
inkscape:snap-global="false"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1031"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-229.26667)">
<flowRoot
xml:space="preserve"
id="flowRoot18"
style="fill:black;stroke:none;stroke-opacity:1;stroke-width:1px;stroke-linejoin:miter;stroke-linecap:butt;fill-opacity:1;font-family:Bitstream Vera Sans;font-style:normal;font-weight:normal;font-size:10px;line-height:125%;letter-spacing:0px;word-spacing:0px"><flowRegion
id="flowRegion20"><rect
id="rect22"
width="130.22333"
height="81.945412"
x="22.550869"
y="26.044664" /></flowRegion><flowPara
id="flowPara24" /></flowRoot> <g
id="g42"
transform="translate(-1.5494384,1.983249)">
<flowRoot
transform="matrix(0.47330966,0,0,0.47330966,-15.084294,244.62861)"
style="font-style:normal;font-weight:normal;font-size:10px;line-height:125%;font-family:'Bitstream Vera Sans';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="flowRoot10"
xml:space="preserve"><flowRegion
id="flowRegion12"><rect
y="33.349876"
x="54.947891"
height="171.19603"
width="160.39702"
id="rect14" /></flowRegion><flowPara
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:170.66667175px;font-family:'Latin Modern Mono Caps';-inkscape-font-specification:'Latin Modern Mono Caps, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#1a1a1a"
id="flowPara16">T</flowPara></flowRoot> <flowRoot
transform="matrix(0.47330966,0,0,0.47330966,-53.418855,239.96835)"
style="font-style:normal;font-weight:normal;font-size:10px;line-height:125%;font-family:'Bitstream Vera Sans';letter-spacing:0px;word-spacing:0px;fill:#48373e;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="flowRoot26"
xml:space="preserve"><flowRegion
style="fill:#48373e"
id="flowRegion28"><rect
style="fill:#48373e"
y="50.818859"
x="182.94789"
height="82.580643"
width="69.240692"
id="rect30" /></flowRegion><flowPara
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:106.66667175px;font-family:'Latin Modern Mono Caps';-inkscape-font-specification:'Latin Modern Mono Caps, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#666666"
id="flowPara32">L</flowPara></flowRoot> </g>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
viewBox="0 0 67.733333 67.733333"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="icon_dark.svg"
inkscape:export-filename="/home/mark/src/todolab/todolab-webextension/icons/icon_dark_64.png"
inkscape:export-xdpi="24"
inkscape:export-ydpi="24">
<defs
id="defs2" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.1484375"
inkscape:cx="92.172705"
inkscape:cy="101.30483"
inkscape:document-units="mm"
inkscape:current-layer="g42"
showgrid="false"
units="px"
width="256px"
showguides="false"
inkscape:snap-text-baseline="false"
inkscape:snap-global="false"
inkscape:pagecheckerboard="true"
inkscape:window-width="1920"
inkscape:window-height="1031"
inkscape:window-x="0"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-229.26667)">
<flowRoot
xml:space="preserve"
id="flowRoot18"
style="fill:black;stroke:none;stroke-opacity:1;stroke-width:1px;stroke-linejoin:miter;stroke-linecap:butt;fill-opacity:1;font-family:Bitstream Vera Sans;font-style:normal;font-weight:normal;font-size:10px;line-height:125%;letter-spacing:0px;word-spacing:0px"><flowRegion
id="flowRegion20"><rect
id="rect22"
width="130.22333"
height="81.945412"
x="22.550869"
y="26.044664" /></flowRegion><flowPara
id="flowPara24" /></flowRoot> <g
id="g42"
transform="translate(-1.5494384,1.983249)">
<flowRoot
transform="matrix(0.47330966,0,0,0.47330966,-15.084294,244.62861)"
style="font-style:normal;font-weight:normal;font-size:10px;line-height:125%;font-family:'Bitstream Vera Sans';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="flowRoot10"
xml:space="preserve"><flowRegion
id="flowRegion12"><rect
y="33.349876"
x="54.947891"
height="171.19603"
width="160.39702"
id="rect14" /></flowRegion><flowPara
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:170.66667175px;font-family:'Latin Modern Mono Caps';-inkscape-font-specification:'Latin Modern Mono Caps, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#ffffff"
id="flowPara16">T</flowPara></flowRoot> <flowRoot
transform="matrix(0.47330966,0,0,0.47330966,-53.418855,239.96835)"
style="font-style:normal;font-weight:normal;font-size:10px;line-height:125%;font-family:'Bitstream Vera Sans';letter-spacing:0px;word-spacing:0px;fill:#48373e;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
id="flowRoot26"
xml:space="preserve"><flowRegion
style="fill:#48373e"
id="flowRegion28"><rect
style="fill:#48373e"
y="50.818859"
x="182.94789"
height="82.580643"
width="69.240692"
id="rect30" /></flowRegion><flowPara
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:106.66667175px;font-family:'Latin Modern Mono Caps';-inkscape-font-specification:'Latin Modern Mono Caps, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;fill:#cccccc"
id="flowPara32">L</flowPara></flowRoot> </g>
</g>
</svg>
......@@ -13,7 +13,9 @@
},
"icons": {
"48": "icons/border-48.png"
"32": "icons/icon_32.png",
"48": "icons/icon_48.png",
"64": "icons/icon_64.png"
},
"permissions": [
......@@ -23,19 +25,31 @@
],
"browser_action": {
"default_icon": "icons/beasts-32.png",
"theme_icons": [{
"light": "icons/beasts-32-light.png",
"dark": "icons/beasts-32.png",
"browser_style": true,
"default_icon": "icons/icon_48.png",
"theme_icons": [
{
"dark": "icons/icon_32.png",
"light": "icons/icon_dark_32.png",
"size": 32
}],
},
{
"dark": "icons/icon_48.png",
"light": "icons/icon_dark_48.png",
"size": 48
},
{
"dark": "icons/icon_64.png",
"light": "icons/icon_dark_64.png",
"size": 64
}
],
"default_title": "Todolab-webext",
"default_popup": "popup/save_page.html"
},
"options_ui": {
"browser_style": true,
"page": "options/options.html"
}
}
......@@ -20,4 +20,3 @@ input {
width: 200px;
height: 2.5em;
}
......@@ -11,11 +11,14 @@
<label>Gitlab URL: <input type="url" id="gitlab-url" ></label>
<label>Project path: <input type="text" id="gitlab-path"></label>
<label>Gitlab token <input type="text" id="gitlab-token"></label>
<label>Gitlab label (optional) <input type="text" id="gitlab-label"></label>
<div>
<b>Project ID: </b>
<div id="gitlab-project-id"> TEST</div>
</div>
<div id="gitlab-project-id"> UNKNOWN</div>
<b>User ID: </b>
<div id="gitlab-user-id"> UNKNOWN</div>
</div>
</section>
<script src="options.js"></script>
</body>
......
const gitlab_url_field = document.querySelector("#gitlab-url");
const gitlab_path_field = document.querySelector("#gitlab-path");
const gitlab_token_field = document.querySelector("#gitlab-token");
const gitlab_label_field = document.querySelector("#gitlab-label");
const gitlab_projid_field = document.querySelector("#gitlab-project-id");
const gitlab_userid_field = document.querySelector("#gitlab-user-id");
function onError(e) {
console.error(e);
......@@ -11,7 +14,9 @@ function restoreOptions(data) {
gitlab_url_field.value = data.gitlab_url || "";
gitlab_path_field.value = data.gitlab_path || "";
gitlab_token_field.value = data.gitlab_token || "";
gitlab_label_field.value = data.gitlab_label || "";
gitlab_projid_field.innerHTML = data.gitlab_project_id || "Not found";
gitlab_userid_field.innerHTML = data.gitlab_user_id || "Not found";
}
/* TODO: We should check issues_enabled and issues_access_level as well */
......@@ -30,22 +35,52 @@ function projectFound(data) {
stored_settings.then(restoreOptions, onError);
}
function userFound(data) {
/* Stash our gitlab user id */
if ('id' in data) {
browser.storage.local.set({
gitlab_user_id: data.id
});
}
/* Now find our project */
let url = gitlab_url_field.value + "/api/v4/projects/" + encodeURIComponent(gitlab_path_field.value)
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application-json',
'Private-Token': gitlab_token_field.value
},
redirect: 'follow',
referrer: 'no-referrer',
}).then(function(response) { return response.json(); })
.then(projectFound)
}
function saveOptions() {
browser.storage.local.set({
gitlab_url: gitlab_url_field.value,
gitlab_path: gitlab_path_field.value,
gitlab_token: gitlab_token_field.value
gitlab_token: gitlab_token_field.value,
gitlab_label: gitlab_label_field.value
});
/* When any of these are updated, re-check our user, then our project */
let url = gitlab_url_field.value + "/api/v4/user"
/* When any of these are updated, if we have them all, try and find
* the project ID. If we can't do that, set the project ID to
* null */
let r = new Request(gitlab_url_field.value + "/api/v4/projects/" + encodeURIComponent(gitlab_path_field.value));
r.headers.append('Private-Token', gitlab_token_field.value);
fetch(r)
.then(function(response) { return response.json(); })
.then(projectFound)
.catch(onError);
fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application-json',
'Private-Token': gitlab_token_field.value
},
redirect: 'follow',
referrer: 'no-referrer',
}).then(function(response) { return response.json(); })
.then(userFound)
}
/*
......@@ -60,3 +95,4 @@ On blur, save the currently selected settings.
gitlab_url_field.addEventListener("blur", saveOptions);
gitlab_path_field.addEventListener("blur", saveOptions);
gitlab_token_field.addEventListener("blur", saveOptions);
gitlab_label_field.addEventListener("blur", saveOptions);
html, body {
width: 100px;
}
.hidden {
display: none;
}
.button {
margin: 3% auto;
padding: 4px;
text-align: center;
font-size: 1.5em;
cursor: pointer;
}
......@@ -3,15 +3,45 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="save_page.css"/>
</head>
<body>
<div id="popup-content">
<button id="save-page">Save Page</button>
<div id="open-list">Open list</div>
<div id="todo-count">Counting TODOs</div>
<header class="panel-section panel-section-header">
<img src="../icons/icon_32.png"/>
<div class="text-section-header">Save Page to TODO</div>
</header>
<div id="issue-options" class="panel-section" style="display: none">
<p>Please configure the extension</p>
<button class="browser-style" style="horizontal-align: center;" id="show-options">Show Options</button>
</div>
<div id="issue-details" class="panel-section panel-section-formElements">
<div class="panel-formElements-item">
<label for="issue-title">Title:</label>
<input type="text" placeholder="Title" id="issue-title" />
</div>
<div class="panel-formElements-item">
<label for="issue-url">Link:</label>
<input type="text" placeholder="URL" id="issue-url" />
</div>
<div id="saving-page" class="panel-formElements-item" style="display: none;">
<p>Saving page</p>
</div>
<div class="panel-formElements-item">
<button class="browser-style" style="horizontal-align: center;" id="save-page">Save Page</button>
</div>
</div>
<footer id="issue-footer" class="panel-section panel-section-footer">
<div style="text-align: center; padding: 12px;" id="todo-count">Counting TODOs</div>
</footer>
<script src="save_page.js"></script>
</body>
......
......@@ -3,6 +3,7 @@
*/
var gitlab_url = "";
var gitlab_path = "";
var gitlab_token = "";
var gitlab_project_id = "";
var gitlab_label = "";
......@@ -12,31 +13,30 @@ function onError(e) {
console.log(e);
}
function issueMade(data) {
console.log(data);
}
function savePage(tabs) {
let tab = tabs[0];
function savePage() {
const title_element = document.querySelector("#issue-title");
const url_element = document.querySelector("#issue-url");
const save_button = document.querySelector("#save-page");
const save_text = document.querySelector("#saving-page");
/* TODO: Change this to pop up a dialog which allows us to choose to save the page
* after editing the details of title and description */
let url = gitlab_url + "/api/v4/projects/" + gitlab_project_id + "/issues";
let data = {};
data['id'] = gitlab_project_id;
data['title'] = tab.title;
data['description'] = tab.url;
data['title'] = title_element.value;
data['description'] = url_element.value;
data['assignee_ids'] = gitlab_user_id;
if (gitlab_label) {
data['labels'] = gitlab_label;
}
let url = gitlab_url + "/api/v4/projects/" + gitlab_project_id + "/issues";
data = JSON.stringify(data);
console.log(data);
save_button.style.display = 'none';
save_text.style.display = 'block';
/* TODO: Add an error handler to the below to show error if we can't submit */
fetch(url, {
method: 'POST',
headers: {
......@@ -48,23 +48,45 @@ function savePage(tabs) {
body: data
})
.then(function(response) { return response.json(); })
.then(issueMade);
.then(function(dat) { window.close(); });
}
function onClick(button) {
if (button.target.id == "save-page") {
/* Want to save the page; find the current URL */
/* Find details from current tab and save the page */
browser.tabs.query({currentWindow: true, active: true})
.then(savePage, console.error);
savePage();
} else if (button.target.id == "todo-count") {
let url = gitlab_url + "/" + gitlab_path + "/issues";
if (gitlab_label) {
url = url + "?label=" + gitlab_label;
}
let creating = browser.tabs.create({ url: url });
creating.then(function(data) { window.close(); });
} else if (button.target.id == "show-options") {
let opening = browser.runtime.openOptionsPage();
opening.then(function(dat) { window.close(); });
}
}
function pageUpdate(data) {
function detailsUpdate(tabs) {
let tab = tabs[0];
const title_element = document.querySelector("#issue-title");
const url_element = document.querySelector("#issue-url");
title_element.value = tab.title;
url_element.value = tab.url;
}
function todoCountUpdate(data) {
const num_todos = document.querySelector("#todo-count");
txt = data.length + " current TODO";
txt = data.length + " current "
if (gitlab_label) {
txt += gitlab_label + " ";
}
txt += "TODO";
if (data.length != 1) {
txt += "s";
}
......@@ -74,16 +96,22 @@ function pageUpdate(data) {
function dataLoad(data) {
gitlab_url = data.gitlab_url || "";
gitlab_path = data.gitlab_path || "";
gitlab_token = data.gitlab_token || "";
gitlab_project_id = data.gitlab_project_id || "";
gitlab_label = data.gitlab_label || "";
gitlab_user_id = data.gitlab_user_id || "";
/* TODO: Allow configuring this */
/*gitlab_label = "Scholarship";*/
if (gitlab_url == "" || gitlab_path == "" || gitlab_project_id == "") {
/* Hide our main sections and show the options */
const issues_div = document.querySelector("#issue-details");
const issues_footer = document.querySelector("#issue-footer");
const issues_options = document.querySelector("#issue-options");
/* TODO FIX THIS TO PULL WHEN WE CONNECT TO THE API */
/*gitlab_user_id = XXX;*/
issues_div.style.display = 'none';
issues_footer.style.display = 'none';
issues_options.style.display = 'block';
if (gitlab_url == "" || gitlab_project_id == "") {
return;
}
......@@ -100,7 +128,11 @@ function dataLoad(data) {
fetch(r)
.then(function(response) { return response.json(); })
.then(pageUpdate);
.then(todoCountUpdate);
/* Find details from current tab and save the page */
browser.tabs.query({currentWindow: true, active: true})
.then(detailsUpdate, console.error);
}
/*
......