redmine time update

This commit is contained in:
Simon Vieille 2015-01-12 20:33:09 +01:00
parent 2e1afa499e
commit 99cd9214c6
3 changed files with 71 additions and 13 deletions

View File

@ -7,6 +7,11 @@
cursor: pointer;
}
#flash {
position: fixed;
top: 50px;
}
.counter {
padding: 10px;
margin-top: -10px;

View File

@ -109,8 +109,8 @@ var App = (function() {
this.loadUpdatePanel = function() {
if (app.counters.length) {
var counters = [];
var today = new Date();
var currentDate = [today.getFullYear(), today.getMonth() + 1, today.getDate()].join('-');
var today = new Date();
var currentDate = [today.getFullYear(), today.getMonth() + 1, today.getDate()].join('-');
for (i in app.counters) {
if (app.counters[i]) {
@ -118,10 +118,10 @@ var App = (function() {
app.counters[i].started = false;
var c = app.counters[i];
c.update = {
time: app.convertTime(c.time + 60, true),
date: currentDate
};
counters.push(c);
time: app.convertTime(c.time + 60, true),
date: currentDate
};
counters.push(c);
}
}
}
@ -130,10 +130,54 @@ var App = (function() {
app.json2html({
counters: counters
}, 'update-panel');
$('#do-update').click(app.doUpdate);
}
}
}
this.doUpdate = function() {
var getInputValue = function(field, issueId) {
return $('#time_' + field + '_' + issueId).val();
}
$('.issue-time').each(function() {
var $form = $(this);
var issueId = $(this).data('issue');
var data = {
time_entry: {
issue_id: issueId,
spent_on: getInputValue('date', issueId),
hours: getInputValue('time', issueId),
comments: getInputValue('comment', issueId),
activity_id: getInputValue('activity', issueId)
}
}
app.post(
'time_entries.xml',
function() {
//$form.remove();
},
data, 'time_entry'
);
});
if (!$('.issue-time').length) {
app.flash('Some forms are not correct.', 'danger');
} else {
app.counters = [];
$('#content').empty();
$('#counters > ul').remove();
app.flash('Redmine has been fully updated!', 'info');
window.setTimeout(function() {
app.loadProjects();
}, 3000);
}
}
this.setTitle = function(name, clickCallback) {
var $oTitle = $('#title');
var $title = $oTitle.clone();
@ -268,6 +312,7 @@ var App = (function() {
$('#content').show();
$('#loading').hide();
console.log('Request failed.');
console.log([uri, type, data]);
app.flash('Request failed.', 'danger');
},
always: function() {}

View File

@ -19,9 +19,9 @@
</div>
</nav>
<div id="content"></div>
<div id="flash"></div>
<div id="content"></div>
<div id="loading">
Loading…
@ -85,7 +85,7 @@
<h3>Redmine updating</h3>
{{#each counters}}
<div class="issue-counter form-horizontal">
<div class="issue-time form-horizontal" data-issue="{{ issue.id }}">
<div class="form-group">
<label for="time_project_name_{{ issue.id }}" class="col-sm-2 control-label">Project</label>
<div class="col-sm-10">
@ -120,10 +120,16 @@
<div class="form-group">
<label for="time_activity_{{ issue.id }}" class="col-sm-2 control-label">Activity*</label>
<div class="col-sm-10">
<select class="form-control" id="time_comment_{{ issue.id }}">
<option value="">Todo</option>
<option value="">Todo</option>
<option value="">Todo</option>
<select class="form-control" id="time_activity_{{ issue.id }}">
<option value="8">Conception</option>
<option value="14">Gestion de projet</option>
<option value="15">Développement Frontend</option>
<option value="9" selected="selected">Développement Backend</option>
<option value="10">Recettage &amp; analyse </option>
<option value="11">Maintenance</option>
<option value="12">Administration système</option>
<option value="16">Veille technologique</option>
<option value="19">Heures sup.</option>
</select>
</div>
</div>
@ -131,6 +137,8 @@
<hr />
</div>
{{/each}}
<p><button type="button" id="do-update" class="btn btn-danger">UPDATE</button></p>
</div>
</script>