diff --git a/css/option.css b/css/option.css index 64475eb..9fd6dd0 100644 --- a/css/option.css +++ b/css/option.css @@ -9,3 +9,6 @@ input { input#save { width: 250px; } +select { + width: 500px; +} diff --git a/js/myscript.coffee b/js/myscript.coffee index 70a518a..1044808 100644 --- a/js/myscript.coffee +++ b/js/myscript.coffee @@ -14,26 +14,26 @@ $ -> repo = localStorage['repo'] if localStorage['token'] token = localStorage['token'] - if localStorage['labels'] + if localStorage['labels'] isnt '' labelStr = localStorage['labels'] + if localStorage['milestone'] + milestone = localStorage['milestone'] url = tab.url title = tab.title issueTitle = "Read later #{title}" body = "[#{title}](#{url})" + query = { + 'title': issueTitle + 'body': body + 'assignee': user + } if labelStr labels = "#{labelStr}".split ',' - query = JSON.stringify({ - 'title': issueTitle - 'body': body - 'assignee': user - 'labels': labels - }) - else - query = JSON.stringify({ - 'title': issueTitle - 'body': body - 'assignee': user - }) + query.labels = labels + $('.message').text typeof(milestone) + ' : ' + milestone + if milestone isnt '0' + query.milestone = milestone + query = JSON.stringify query url = "https://api.github.com/repos/#{user}/#{repo}/issues?access_token=#{token}" $.ajax 'async': false diff --git a/js/myscript.js b/js/myscript.js index 83c46da..e97a6a4 100644 --- a/js/myscript.js +++ b/js/myscript.js @@ -10,7 +10,7 @@ $(function() { return $(document).on('click', '#issue-button', function() { return ws.getCurrent(function(window) { return tbs.getSelected(window.id, function(tab) { - var body, issueTitle, labelStr, labels, query, repo, title, token, url, user; + var body, issueTitle, labelStr, labels, milestone, query, repo, title, token, url, user; user = ''; repo = ''; token = ''; @@ -23,28 +23,30 @@ $(function() { if (localStorage['token']) { token = localStorage['token']; } - if (localStorage['labels']) { + if (localStorage['labels'] !== '') { labelStr = localStorage['labels']; } + if (localStorage['milestone']) { + milestone = localStorage['milestone']; + } url = tab.url; title = tab.title; issueTitle = "Read later " + title; body = "[" + title + "](" + url + ")"; + query = { + 'title': issueTitle, + 'body': body, + 'assignee': user + }; if (labelStr) { labels = ("" + labelStr).split(','); - query = JSON.stringify({ - 'title': issueTitle, - 'body': body, - 'assignee': user, - 'labels': labels - }); - } else { - query = JSON.stringify({ - 'title': issueTitle, - 'body': body, - 'assignee': user - }); + query.labels = labels; + } + $('.message').text(typeof milestone + ' : ' + milestone); + if (milestone !== '0') { + query.milestone = milestone; } + query = JSON.stringify(query); url = "https://api.github.com/repos/" + user + "/" + repo + "/issues?access_token=" + token; return $.ajax({ 'async': false, diff --git a/js/option.coffee b/js/option.coffee index 30f24a2..56d62c4 100644 --- a/js/option.coffee +++ b/js/option.coffee @@ -1,4 +1,38 @@ $ -> + # Set Milestones + setMilestone = -> + user = localStorage['user'] + repo = localStorage['repo'] + token = localStorage['token'] + milestone = localStorage['milestone'] + if user == null || user == 'Enter the GitHub user name' + user = null + if repo == null || repo == 'Enter the GitHub repositori name' + repo = null + if user && repo + query = JSON.stringify({ + 'state': 'all' + 'sort': 'due_on' + 'direction': 'asc' + }) + url = "https://api.github.com/repos/#{user}/#{repo}/milestones?access_token=#{token}" + $.ajax + 'async': false + 'url': url + 'type': 'get' + 'data': query + 'dataType': 'json' + 'success': (res) -> + $('#milestone option').remove() + $('#milestone').append $('', { value: 0, text: 'Choose Milestone'}) + for key, value of res + $('#milestone').append $('', { value: value['number'], text: value['title']}) + $('#milestone').val(milestone) + $('.milestone').show() + 'error': (res) -> + # TODO: ここは直接メッセージが出るようにしよう + console.log url + if localStorage['user'] $('#user').val(localStorage['user']) else @@ -13,11 +47,20 @@ $ -> $('#token').val('Enter the GitHub Personal access token') if localStorage['labels'] $('#labels').val(localStorage['labels']) + else if localStorage['labels'] is '' + $('#labels').val('') else $('#labels').val('readlate, memo') + if localStorage['milestone'] is '0' + $('.milestone').hide() + else + setMilestone() $('#save').on 'click', -> localStorage['user'] = $('#user').val() localStorage['repo'] = $('#repo').val() localStorage['token'] = $('#token').val() localStorage['labels'] = $('#labels').val() + localStorage['milestone'] = $('#milestone').val() + # Show Milestones + setMilestone() diff --git a/js/option.js b/js/option.js index 2353b0e..3f013ff 100644 --- a/js/option.js +++ b/js/option.js @@ -1,4 +1,53 @@ $(function() { + var setMilestone; + setMilestone = function() { + var milestone, query, repo, token, url, user; + user = localStorage['user']; + repo = localStorage['repo']; + token = localStorage['token']; + milestone = localStorage['milestone']; + if (user === null || user === 'Enter the GitHub user name') { + user = null; + } + if (repo === null || repo === 'Enter the GitHub repositori name') { + repo = null; + } + if (user && repo) { + query = JSON.stringify({ + 'state': 'all', + 'sort': 'due_on', + 'direction': 'asc' + }); + url = "https://api.github.com/repos/" + user + "/" + repo + "/milestones?access_token=" + token; + return $.ajax({ + 'async': false, + 'url': url, + 'type': 'get', + 'data': query, + 'dataType': 'json', + 'success': function(res) { + var key, value; + $('#milestone option').remove(); + $('#milestone').append($('', { + value: 0, + text: 'Choose Milestone' + })); + for (key in res) { + value = res[key]; + $('#milestone').append($('', { + value: value['number'], + text: value['title'] + })); + } + $('#milestone').val(milestone); + return $('.milestone').show(); + }, + 'error': function(res) { + return console.log(url); + } + }); + } + }; if (localStorage['user']) { $('#user').val(localStorage['user']); } else { @@ -16,13 +65,22 @@ $(function() { } if (localStorage['labels']) { $('#labels').val(localStorage['labels']); + } else if (localStorage['labels'] === '') { + $('#labels').val(''); } else { $('#labels').val('readlate, memo'); } + if (localStorage['milestone'] === '0') { + $('.milestone').hide(); + } else { + setMilestone(); + } return $('#save').on('click', function() { localStorage['user'] = $('#user').val(); localStorage['repo'] = $('#repo').val(); localStorage['token'] = $('#token').val(); - return localStorage['labels'] = $('#labels').val(); + localStorage['labels'] = $('#labels').val(); + localStorage['milestone'] = $('#milestone').val(); + return setMilestone(); }); }); diff --git a/options.html b/options.html index a237ec8..be85789 100644 --- a/options.html +++ b/options.html @@ -19,6 +19,11 @@ GitHub Personal access token Setting lables + + Setting Milestone + + +