Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add milestone setting #27

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions css/option.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ input {
input#save {
width: 250px;
}
select {
width: 500px;
}
26 changes: 13 additions & 13 deletions js/myscript.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 16 additions & 14 deletions js/myscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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,
Expand Down
43 changes: 43 additions & 0 deletions js/option.coffee
Original file line number Diff line number Diff line change
@@ -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 $('<option>', { value: 0, text: 'Choose Milestone'})
for key, value of res
$('#milestone').append $('<option>', { 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
Expand All @@ -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()
60 changes: 59 additions & 1 deletion js/option.js
Original file line number Diff line number Diff line change
@@ -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($('<option>', {
value: 0,
text: 'Choose Milestone'
}));
for (key in res) {
value = res[key];
$('#milestone').append($('<option>', {
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 {
Expand All @@ -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();
});
});
5 changes: 5 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ <h3> GitHub Personal access token </h3>
<input id="token" type="text" />
<h3> Setting lables </h3>
<input id="labels" type="text" /><br />
<div class='milestone'>
<h3> Setting Milestone</h3>
<select id="milestone">
</select>
</div><br />
<input id="save" type="button" value="Save" />
</div>
</body>
Expand Down