From 866d59fe8643a6b261f33f83e6eba34eae4a0db8 Mon Sep 17 00:00:00 2001 From: Nazar Kanaev Date: Wed, 1 Jul 2020 17:22:06 +0100 Subject: [PATCH] ui: create new feed --- template/index.html | 41 ++++++++++++++++-------------- template/static/javascripts/api.js | 25 ++++++++++++++++++ template/static/javascripts/app.js | 16 ++++++++++++ 3 files changed, 63 insertions(+), 19 deletions(-) create mode 100644 template/static/javascripts/api.js diff --git a/template/index.html b/template/index.html index 53e4559..c44a16e 100644 --- a/template/index.html +++ b/template/index.html @@ -92,26 +92,28 @@ - +
- - - - - +
+ + + + + +
@@ -167,6 +169,7 @@ + diff --git a/template/static/javascripts/api.js b/template/static/javascripts/api.js new file mode 100644 index 0000000..e145a77 --- /dev/null +++ b/template/static/javascripts/api.js @@ -0,0 +1,25 @@ +"use strict"; + +(function() { + var api = function(method, endpoint, data) { + var promise = fetch(endpoint, { + method: method, + headers: {'content-type': 'application/json'}, + body: JSON.stringify(data), + }) + return promise.then(function(res) { + if (res.ok) return res.json() + }) + } + + window.api = { + feeds: { + list: function() { + return api('get', '/api/feeds') + }, + create: function(data) { + return api('post', '/api/feeds', data) + }, + } + } +})() diff --git a/template/static/javascripts/app.js b/template/static/javascripts/app.js index 9c015ca..78c30bd 100644 --- a/template/static/javascripts/app.js +++ b/template/static/javascripts/app.js @@ -32,6 +32,7 @@ var vm = new Vue({ 'itemSelected': null, 'settings': 'manage', 'newFolderTitle': null, + 'loading': {newfeed: 0}, } }, computed: { @@ -95,5 +96,20 @@ var vm = new Vue({ this.feeds = this.feeds.filter(function(f) { f.id != feed.id }) } }, + createFeed: function(event) { + var form = event.target + var data = { + url: form.querySelector('input[name=url]').value, + folder_id: parseInt(form.querySelector('select[name=folder_id]').value) || null, + } + this.loading.newfeed = true + var vm = this + api.feeds.create(data).then(function(result) { + if (result.status === 'success') { + vm.$bvModal.hide('settings-modal') + } + vm.loading.newfeed = false + }) + }, } })