Skip to content

Commit

Permalink
fix empty options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr. Funk committed Jun 21, 2019
1 parent deb214f commit 47deb81
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/content/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ function getKanbanDetails () {
if (result && result[optionsKey] && result[optionsKey].length) {
currentOptions = result[optionsKey]
}
var ignoreList = ["github.com", "bitbucket.org", "gitlab.com", "gitea.com"],
host = window.location.host

var host = window.location.host

if (currentOptions && currentOptions.length) {
if (ignoreList.indexOf(host) === -1 && currentOptions && currentOptions.length) {
for (let i = 0; i < currentOptions.length; i++) {
// if host = option url then set host to type
if (currentOptions[i].url === host) {
Expand Down
1 change: 1 addition & 0 deletions src/js/display/pages/board/root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default {
vm.oToken = currentOptions[optionIndex].oToken
if (currentOptions[optionIndex].repos && currentOptions[optionIndex].repos[vm.repoName] && currentOptions[optionIndex].repos[vm.repoName].stages && currentOptions[optionIndex].repos[vm.repoName].stages.length > 0) {
vm.stages = currentOptions[optionIndex].repos[vm.repoName].stages
vm.stages.unshift("Backlog")
}
}
} else {
Expand Down
37 changes: 30 additions & 7 deletions src/js/display/pages/settings/root.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<div>settings:
<!-- <span v-if="currentOptions">{{currentOptions[optionIndex]}}</span> -->
<!-- <span v-if="currentOptions && optionIndex !== -1">{{currentOptions[optionIndex]}}</span> -->
<!-- <br> -->
<!-- <span v-if="currentOptions && currentOptions[optionIndex].repos && currentOptions[optionIndex].repos[repoName]">{{currentOptions[optionIndex].repos[repoName]}} {{currentOptions[optionIndex].repos[repoName].stages}}</span> -->
<!-- {{optionIndex}} -->
<!-- <span v-if="currentOptions && optionIndex !== -1 && currentOptions[optionIndex].repos && currentOptions[optionIndex].repos[repoName]">{{currentOptions[optionIndex].repos[repoName]}} {{currentOptions[optionIndex].repos[repoName].stages}}</span> -->
<div>
<h3>Kanban Labels:</h3>
<ul v-if="currentOptions && currentOptions[optionIndex].repos && currentOptions[optionIndex].repos[repoName]">
<ul v-if="currentOptions && optionIndex !== -1 && currentOptions[optionIndex].repos && currentOptions[optionIndex].repos[repoName]">
<li v-for="(stage, index) in currentOptions[optionIndex].repos[repoName].stages" v-bind:key="index">
<div class="ui label has-emoji" v-bind:style="labelStyle(stage)" style="color: #000">
<i class="octicon octicon-tag"></i> {{stage}}
Expand Down Expand Up @@ -61,6 +62,8 @@ export default {
repo = url[2],
data = user + "/" + repo
chrome.storage.sync.get([optionsKey], function (result) {
// console.log("result is")
// console.log(result)
if (result && result[optionsKey] && result[optionsKey].length) {
vm.currentOptions = result[optionsKey]
vm.optionIndex = vm.currentOptions.findIndex(x => x.url.indexOf(window.location.host) !== -1)
Expand All @@ -83,7 +86,7 @@ export default {
this.labels = response.data
// TODO: populate this.av from this.labels and this.currentoptions
if (vm.currentOptions && vm.currentOptions[vm.optionIndex].repos && vm.currentOptions[vm.optionIndex].repos[vm.repoName] && vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages && vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages.length > 0) {
if (vm.currentOptions && vm.optionIndex !== -1 && vm.currentOptions[vm.optionIndex].repos && vm.currentOptions[vm.optionIndex].repos[vm.repoName] && vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages && vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages.length > 0) {
vm.availableLabels = this.labels.filter(function (el) {
return vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages.indexOf(el.name) === -1
})
Expand Down Expand Up @@ -175,18 +178,38 @@ export default {
// var index = this.currentOptions.findIndex(x => window.location.host.indexOf(x.url) !== -1)
// console.log("inde:" + index)
// console.log(this.currentOptions)
if (!this.currentOptions) {
this.currentOptions = []
}
if (this.optionIndex !== -1) {
if (this.optionIndex !== null && this.optionIndex !== -1) {
if (!this.currentOptions[this.optionIndex].repos) {
this.currentOptions[this.optionIndex].repos = {}
}
if (!this.currentOptions[this.optionIndex].repos[this.repoName]) {
this.currentOptions[this.optionIndex].repos[this.repoName] = {
stages: [this.label.name]
stages: [label.name]
}
} else {
this.currentOptions[this.optionIndex].repos[this.repoName].stages.push(label.name)
}
} else {
var ignoreList = ["github.com", "bitbucket.org", "gitlab.com", "gitea.com"],
host = window.location.host
if (ignoreList.indexOf(host) !== -1) {
this.currentOptions.push({
url: host,
repos: {
[this.repoName]: {
stages: [label.name]
}
}
})
this.optionIndex = this.currentOptions.findIndex(x => x.url.indexOf(host) !== -1)
}
// TODO init from scratch
}
this.currentOptions = JSON.parse(JSON.stringify(this.currentOptions))
// console.log(this.currentOptions)
Expand All @@ -195,7 +218,7 @@ export default {
[optionsKey]: vm.currentOptions
}, function () {
})
// console.log(this.availableLabels)
// TODO: remove from available
this.availableLabels = this.labels.filter(function (el) {
return vm.currentOptions[vm.optionIndex].repos[vm.repoName].stages.indexOf(el.name) === -1
Expand Down
2 changes: 1 addition & 1 deletion src/manifest-main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

module.exports = {
name: 'Git Kanban Enhance',
version: '0.0.3',
version: '0.0.4',
description: 'Kanban extensions for github, gitlab, gitea, and bitbucket',
author: "http://github.com/lastlink",
manifest_version: 2,
Expand Down
25 changes: 13 additions & 12 deletions src/tab/root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
},
methods: {
retrieveManifest: function () {
// console.log(this.retrieveManifest.name)
var vm = this
this.loading = true
Expand All @@ -111,18 +112,18 @@
for (i; i < l; i++) {
myClasses[i].style.display = ''
}
// restore urls
chrome.storage.sync.get([optionsKey], function (result) {
if (result && result[optionsKey] && result[optionsKey].length) {
vm.currentOptions = result[optionsKey]
} else {
vm.currentOptions = []
}
// document.getElementById('color').value = items.favoriteColor;
// document.getElementById('like').checked = items.likesColor;
})
}
// restore urls
chrome.storage.sync.get([optionsKey], function (result) {
// console.log(result)
if (result && result[optionsKey] && result[optionsKey].length) {
vm.currentOptions = result[optionsKey]
} else {
vm.currentOptions = []
}
// document.getElementById('color').value = items.favoriteColor;
// document.getElementById('like').checked = items.likesColor;
})
// response = response
})
}, // end retrieve manifest
Expand Down Expand Up @@ -153,7 +154,7 @@
exportOptions () {
console.log(this.exportOptions.name)
if (!this.currentOptions) {
console.warn("no import json")
console.warn("no export json")
return
}
const data = JSON.stringify(this.currentOptions)
Expand Down

0 comments on commit 47deb81

Please sign in to comment.