Skip to content

Commit

Permalink
Merge pull request #61 from Simounet/feature/debug
Browse files Browse the repository at this point in the history
Fix #54 User option for debugging purpose added
  • Loading branch information
Simounet authored Mar 2, 2017
2 parents bd5e44e + a62eeb7 commit d0ed272
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
1 change: 1 addition & 0 deletions wallabagger/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ browser.commands.onCommand.addListener(function (command) {
});

GetApi().then(api => {
api.resetDebug();
if (api.data.AllowExistCheck) {
browser.tabs.onActivated.addListener(function (activeInfo) {
browser.browserAction.setIcon({ path: icon.default });
Expand Down
15 changes: 13 additions & 2 deletions wallabagger/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var OptionsController = function () {
// this.tokenExpiresInput = document.getElementById("tokenexpired-input");
this.allowSpaceCheck = document.getElementById('allow-space-checkbox');
this.allowExistCheck = document.getElementById('allow-exist-checkbox');
this.debugEl = document.getElementById('debug');
this.saveToFileButton = document.getElementById('saveToFile-button');
this.loadFromFileButton = document.getElementById('loadFromFile-button');
this.clearButton = document.getElementById('clear-button');
Expand Down Expand Up @@ -65,6 +66,7 @@ OptionsController.prototype = {

allowSpaceCheck: null,
allowExistCheck: null,
debugEl: null,
httpsButton: null,
httpsMessage: null,

Expand All @@ -73,6 +75,7 @@ OptionsController.prototype = {
addListeners_: function () {
this.allowSpaceCheck.addEventListener('click', this.allowSpaceCheckClick.bind(this));
this.allowExistCheck.addEventListener('click', this.allowExistCheckClick.bind(this));
this.debugEl.addEventListener('click', this.debugClick.bind(this));
this.protocolCheck_.addEventListener('click', this.handleProtocolClick.bind(this));
// this.savebutton_.addEventListener('click', this.saveClick_.bind(this));
this.checkurlbutton_.addEventListener('click', this.checkUrlClick.bind(this));
Expand Down Expand Up @@ -124,9 +127,11 @@ OptionsController.prototype = {
let fileReader = new FileReader();
fileReader.onload = function (fileLoadedEvent) {
let textFromFileLoaded = fileLoadedEvent.target.result;
console.log(textFromFileLoaded);
let obj = JSON.parse(textFromFileLoaded);
console.log(obj);
if(this.api.data.Debug === true) {
console.log(textFromFileLoaded);
console.log(obj);
}
this.api.set(obj);
this.setFields(obj);
this.api.save();
Expand Down Expand Up @@ -165,6 +170,11 @@ OptionsController.prototype = {
}
},

debugClick: function () {
this.api.set({ Debug: this.debugEl.checked });
this.api.save();
},

wallabagApiTokenGot: function () {
this.api.save();

Expand Down Expand Up @@ -353,6 +363,7 @@ OptionsController.prototype = {

this.allowSpaceCheck.checked = data.AllowSpaceInTags;
this.allowExistCheck.checked = data.AllowExistCheck;
this.debugEl.checked = data.Debug;
},

init: function () {
Expand Down
8 changes: 6 additions & 2 deletions wallabagger/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,15 @@ PopupController.prototype = {
apiAuthorised.then(data => this.activeTab())
.then(tab => {
this.showInfo('Saving the page to wallabag ...');
console.log(tab.url);
if(this.api.data.Debug === true) {
console.log(tab.url);
}
return this.api.SavePage(tab.url);
})
.then(data => {
console.log(data);
if(this.api.data.Debug === true) {
console.log(data);
}
if (data != null) {
this.articleId = data.id;
this.cardTitle.textContent = data.title;
Expand Down
39 changes: 23 additions & 16 deletions wallabagger/js/wallabag-api.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
var WallabagApi = function () { };

const emptyData = {
Url: null,
ApiVersion: null,
ClientId: null,
ClientSecret: null,
UserLogin: null,
UserPassword: null,
ApiToken: null,
RefreshToken: null,
ExpireDateMs: null,
AllowSpaceInTags: null,
AllowExistCheck: null
};

WallabagApi.prototype = {

data: emptyData,
defaultValues: {
Url: null,
ApiVersion: null,
ClientId: null,
ClientSecret: null,
UserLogin: null,
UserPassword: null,
ApiToken: null,
RefreshToken: null,
ExpireDateMs: null,
AllowSpaceInTags: null,
AllowExistCheck: null,
Debug: false
},

data: {},

fetchApi: null,

tags: [],

init: function () {
Object.assign(this.data, this.defaultValues);
this.fetchApi = new FetchApi();
return this.load();
},

resetDebug: function() {
this.data.Debug = this.defaultValues.Debug;
this.save();
},

save: function () {
chrome.storage.local.set({ 'wallabagdata': this.data });
},
Expand Down Expand Up @@ -71,7 +78,7 @@ WallabagApi.prototype = {
},

clear: function () {
this.set(emptyData);
this.set(this.defaultValues);
},

set: function (params) {
Expand Down
7 changes: 7 additions & 0 deletions wallabagger/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@
<i class="form-icon"></i>Indicate if page already saved (this sends URL of each tab to wallabag, use HTTPS protocol for better security!)
</label>
</div>

<div class="form-group">
<label class="form-switch">
<input type="checkbox" id="debug"/>
<i class="form-icon"></i>Enable this only if developers told you to.
</label>
</div>
</section>
</div>
</div>
Expand Down

0 comments on commit d0ed272

Please sign in to comment.