Created
January 18, 2018 10:23
-
-
Save jacquarg/8b29e279d37d4f72141f5b6c5648a15a to your computer and use it in GitHub Desktop.
Add manage konnector page to cozy-collect (git patch)
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
From 30cfa75c352d74c56ebe4f56c3109d73ae0a04bc Mon Sep 17 00:00:00 2001 | |
From: jacquarg <[email protected]> | |
Date: Mon, 4 Dec 2017 14:53:23 +0100 | |
Subject: [PATCH] Add managekonnectors page. | |
--- | |
managekonnectors/app.js | 36 ++++++++++++++++++++++++++++++++++++ | |
managekonnectors/index.html | 33 +++++++++++++++++++++++++++++++++ | |
manifest.webapp | 5 +++++ | |
package.json | 1 + | |
4 files changed, 75 insertions(+) | |
create mode 100644 managekonnectors/app.js | |
create mode 100644 managekonnectors/index.html | |
diff --git a/managekonnectors/app.js b/managekonnectors/app.js | |
new file mode 100644 | |
index 0000000..059d1bb | |
--- /dev/null | |
+++ b/managekonnectors/app.js | |
@@ -0,0 +1,36 @@ | |
+'use-strict' | |
+ | |
+document.addEventListener('DOMContentLoaded', () => { | |
+ const app = document.querySelector('[role=application]') | |
+ cozy.client.init({ | |
+ cozyURL: '//' + app.dataset.cozyDomain, | |
+ token: app.dataset.cozyToken, | |
+ }) | |
+ | |
+ | |
+ window.cozy.bar.init({ appName: 'Manage konnectors' }) | |
+ | |
+ | |
+ document.getElementById('update').onclick = () => { | |
+ displayMessage('Updating konnector') | |
+ work('PUT') | |
+ } | |
+ | |
+ document.getElementById('install').onclick = () => { | |
+ displayMessage('Installing konnector ...') | |
+ work('POST') | |
+ } | |
+}) | |
+ | |
+function work (verb) { | |
+ const slug = document.getElementById('slug').value | |
+ const source = document.getElementById('repositoryuri').value | |
+ return cozy.client.fetchJSON(verb, `/konnectors/${slug}?Source=${encodeURIComponent(source)}`) //, '', { headers: { 'Accept': 'text/event-stream' } }) | |
+ .then(() => displayMessage('done')) | |
+ .catch((err) => displayMessage(err)) | |
+} | |
+ | |
+function displayMessage (msg) { | |
+ const messageElem = document.getElementById('message') | |
+ messageElem.innerHTML = msg | |
+} | |
diff --git a/managekonnectors/index.html b/managekonnectors/index.html | |
new file mode 100644 | |
index 0000000..1b93f11 | |
--- /dev/null | |
+++ b/managekonnectors/index.html | |
@@ -0,0 +1,33 @@ | |
+<!DOCTYPE html> | |
+<html lang="fr"> | |
+<head> | |
+ <!-- {{.CozyClientJS}} sera remplacé par la balise HTML injectant le script de la bibliothèque cozy-client-js. --> | |
+ {{.CozyClientJS}} | |
+ {{.CozyBar}} | |
+ <title>Manage konnectors</title> | |
+</head> | |
+<body> | |
+ <div role="application" data-cozy-token="{{.Token}}" data-cozy-domain="{{.Domain}}" class="container-fluid" data-cozy-app-name="{{.AppName}}" > | |
+ <H1>Install, update manually your konnectors !</H1> | |
+ <H2>Update</H2> | |
+ <P>Fill up the slug (contraints ?) field, and press update !</P> | |
+ | |
+ <H2>Install</H2> | |
+ <P>Fill up the slug field, and the repository url field, and press install ! Be carrefull, to use this konnector with cozy-collect, it as to be added to the <a href="https://github.com/cozy/cozy-collect/blob/master/src/config/konnectors.json">konnectors.json</a> file of the branch you will use.</p> | |
+ | |
+ <form> | |
+ <fieldset> | |
+ <label>Slug : <input type="text" id="slug"></label> | |
+ <input type="button" id="update" value="Update" > | |
+ </fieldset> | |
+ <fieldset> | |
+ <label>URI : <input type="uri" id="repositoryuri"></label> | |
+ <input type="button" id="install" value="Install" > | |
+ </fieldset> | |
+ | |
+ </form> | |
+ <div>Message : <b><span id="message" ></span></b></div> | |
+ </div> | |
+ <script src='./app.js' ></script> | |
+</body> | |
+</html> | |
diff --git a/manifest.webapp b/manifest.webapp | |
index c4fc4a3..90a1a04 100644 | |
--- a/manifest.webapp | |
+++ b/manifest.webapp | |
@@ -72,6 +72,11 @@ | |
"folder": "/services", | |
"index": "index.html", | |
"public": false | |
+ }, | |
+ "/managekonnectors": { | |
+ "folder": "/managekonnectors", | |
+ "index": "index.html", | |
+ "public": false | |
} | |
}, | |
"intents": [{ | |
diff --git a/package.json b/package.json | |
index 9c476da..270241b 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -3,6 +3,7 @@ | |
"version": "1.0.2", | |
"main": "src/index.jsx", | |
"scripts": { | |
+ "build:managekonnectors": "cp -r managekonnectors build/", | |
"build": "npm run build:browser", | |
"build:browser": "NODE_ENV=browser:production npm run commons:build", | |
"build:mobile": "NODE_ENV=mobile:production npm run commons:build", | |
-- | |
2.11.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment