Skip to content

Commit ba56ee7

Browse files
committed
Settings from cabalilites
1 parent 81ffe1c commit ba56ee7

File tree

5 files changed

+645
-42
lines changed

5 files changed

+645
-42
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<% if User.current.allowed_to?(:view_gtt_print, @project) and @issue.present? %>
22
<%= content_tag(:h3, l(:label_gtt_print_title)) %>
33
<form action="<%= Setting.plugin_redmine_gtt_print['default_print_server'] %>" method="post" class="print_box">
4-
<select name="template">
5-
</select>
4+
<select name="template"></select><br>
5+
<select name="layout"></select>
6+
<select name="format"></select>
7+
<textarea name="freetext"></textarea>
68
<%= content_tag(:input, nil, type: "button", value: l(:button_gtt_print_submit)) %>
79
</form>
810
<% end %>

assets/javascripts/gtt_print.js

Lines changed: 129 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,163 @@
11
$(function() {
2+
3+
var capabilities = false;
4+
25
if ($('form.print_box').length > 0) {
36
var server = $('form.print_box').attr('action').replace(/\/?$/, '/');
47

58
$.getJSON(server + "print/apps.json", function (data) {
69
$.each(data, function(key, value) {
710
// "default" profile does not really work for some reason
8-
if (value != "default") {
9-
var option = $("<option></option>").attr("value",value).text(value);
10-
$('form.print_box select').append(option);
11+
if (value != "default" && value.split("_")[0] != "DEMO") {
12+
var option = $("<option></option>").attr("value",value).text(value.split("_")[1]);
13+
$('form.print_box select[name=template]').append(option);
1114
}
1215
});
16+
$('form.print_box select[name=template]').change();
1317
});
1418
}
1519

16-
$(document).on('click', '.print_box input[type=button]', function (e) {
20+
var apikey = "";
21+
$.get('/my/api_key').done(function(data){
22+
apikey = $('#content > div.box > pre', $(data)).first().text();
23+
});
1724

18-
var appId = $('form.print_box select').val();
25+
$('form.print_box select').on('change', function (e) {
26+
$.ajax({
27+
type: 'GET',
28+
url: server + "print/" + $('form.print_box select').val() + "/capabilities.json",
29+
dataType: 'json',
30+
success: function (data) {
31+
32+
$.each(data.formats, function(key, value) {
33+
var option = $("<option></option>").attr("value",value).text(value);
34+
$('form.print_box select[name=format]').append(option);
35+
$('form.print_box select[name=format]').val("pdf");
36+
});
37+
38+
$.each(data.layouts, function(key, value) {
39+
var option = $("<option></option>").attr("value",key).text(value.name);
40+
$('form.print_box select[name=layout]').append(option);
41+
});
1942

43+
capabilities = data;
44+
}
45+
});
46+
});
47+
48+
$('form.print_box input[type=button]').on('click', function (e) {
49+
var appId = $('form.print_box select').val();
2050
$.ajax({
2151
type: 'GET',
2252
url: server + "print/" + appId + "/exampleRequest.json",
2353
dataType: 'json',
2454
success: function (data) {
25-
requestPrint(appId, JSON.parse(data.requestData));
55+
requestPrint(appId, capabilities, JSON.parse(data.requestData));
2656
}
2757
});
28-
29-
return false;
3058
});
3159

32-
var requestPrint = function (id, requestData) {
60+
var requestPrint = function (id, config, requestData) {
3361

3462
// Defaults
35-
var format = "pdf";
36-
var layout = 0;
63+
var format = $('form.print_box select[name=format]').val();
64+
var layout = $('form.print_box select[name=layout]').val();
3765

38-
var paramObj = {};
39-
$.each($('#issue-form').serializeArray(), function(_, kv) {
40-
paramObj[kv.name] = kv.value;
41-
});
66+
// var paramObj = {};
67+
// $.each($('#issue-form').serializeArray(), function(_, kv) {
68+
// paramObj[kv.name] = kv.value;
69+
// });
70+
71+
$.ajax({
72+
type: 'GET',
73+
url: $('#issue-form').attr("action") + ".json",
74+
headers: {'X-Redmine-API-Key': apikey},
75+
data: {
76+
include: "attachments,journals"
77+
},
78+
dataType: 'json',
79+
success: function (data) {
4280

43-
// Apply geo data if exists
44-
if (requestData.attributes.map.layers[0].geoJson && paramObj["issue[geojson]"]) {
45-
var feature = (new ol.format.GeoJSON()).readFeature(
46-
JSON.parse(paramObj["issue[geojson]"])
47-
);
48-
feature.set('subject', paramObj["issue[subject]"]);
49-
feature.getGeometry().transform('EPSG:4326','EPSG:3857');
81+
// Handle each available attribute
82+
$.each(config.layouts[layout].attributes, function(key, obj) {
5083

51-
requestData.attributes.map.layers[0].geoJson = JSON.parse((new ol.format.GeoJSON()).writeFeatures([feature]));
52-
requestData.attributes.map.center = ol.extent.getCenter(feature.getGeometry().getExtent());
53-
}
84+
// Apply geo data if exists
85+
if (obj.name === "map" && data.issue.geojson) {
86+
if(requestData.attributes.map.layers[0].geoJson) {
87+
var feature = (new ol.format.GeoJSON()).readFeature(data.issue.geojson);
88+
feature.set('foo','bar');
89+
feature.getGeometry().transform('EPSG:4326','EPSG:3857');
5490

55-
// Apply template variables
56-
requestData.attributes.title = paramObj["issue[subject]"];
91+
requestData.attributes.map.layers[0].geoJson = JSON.parse((new ol.format.GeoJSON()).writeFeatures([feature]));
92+
requestData.attributes.map.center = ol.extent.getCenter(feature.getGeometry().getExtent());
93+
}
94+
return true;
95+
}
5796

58-
console.log(requestData);
59-
var startTime = new Date().getTime();
97+
switch (obj.name) {
98+
case 'scalebar':
99+
// currently nothing to do
100+
break;
60101

61-
$.ajax({
62-
type: 'POST',
63-
url: server + "print/" + id + "/report." + format,
64-
data: {
65-
spec: JSON.stringify(requestData)
66-
},
67-
success: function (response) {
68-
downloadWhenReady(startTime, response.ref);
69-
},
70-
error: function (data) {
71-
console.log(data);
102+
case 'freetext':
103+
requestData.attributes[obj.name] = $('form.print_box textarea').val();
104+
break;
105+
106+
case 'assigned_to':
107+
case 'author':
108+
case 'priority':
109+
case 'project':
110+
case 'status':
111+
case 'tracker':
112+
requestData.attributes[obj.name] = data.issue[obj.name].name;
113+
break;
114+
115+
case 'created_on':
116+
case 'updated_on':
117+
case 'due_date':
118+
case 'start_date':
119+
requestData.attributes[obj.name] = moment(data.issue[obj.name]).format('YYYY-MM-DD');
120+
break;
121+
122+
case 'description':
123+
case 'done_ratio':
124+
case 'estimated_hours':
125+
case 'id':
126+
case 'subject':
127+
case 'total_estimated_hours':
128+
requestData.attributes[obj.name] = data.issue[obj.name];
129+
break;
130+
131+
default:
132+
requestData.attributes[obj.name] = obj.default;
133+
break;
134+
}
135+
136+
if (data.issue.custom_fields) {
137+
$.each(data.issue.custom_fields, function (key,field) {
138+
if (obj.name === field.name) {
139+
requestData.attributes[obj.name] = field.value;
140+
}
141+
});
142+
}
143+
});
144+
145+
console.log(requestData);
146+
var startTime = new Date().getTime();
147+
148+
$.ajax({
149+
type: 'POST',
150+
url: server + "print/" + id + "/report." + format,
151+
data: {
152+
spec: JSON.stringify(requestData)
153+
},
154+
success: function (response) {
155+
downloadWhenReady(startTime, response.ref);
156+
},
157+
error: function (data) {
158+
console.log(data);
159+
}
160+
});
72161
}
73162
});
74163
};

assets/javascripts/moment.min.js

Lines changed: 505 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/stylesheets/gtt_print.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
/* CSS for gtt_print plugin */
2+
form.print_box textarea{
3+
margin-top: 10px;
4+
display: block;
5+
width: 75%;
6+
min-height: 5.7em;
7+
}

lib/redmine_gtt_print/view_hooks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class ViewHooks < Redmine::Hook::ViewListener
33

44
render_on :view_layouts_base_html_head, inline: <<-END
55
<%= stylesheet_link_tag 'gtt_print', plugin: 'redmine_gtt_print' %>
6+
<%= javascript_include_tag 'moment.min', plugin: 'redmine_gtt_print' %>
67
<%= javascript_include_tag 'gtt_print', plugin: 'redmine_gtt_print' %>
78
END
89

0 commit comments

Comments
 (0)