##// END OF EJS Templates
default-reviewers: add reason when manually adding reviewers after creating a PR....
marcink -
r942:cde81eb1 default
parent child Browse files
Show More
@@ -1,217 +1,219 b''
1 1 // # Copyright (C) 2010-2016 RhodeCode GmbH
2 2 // #
3 3 // # This program is free software: you can redistribute it and/or modify
4 4 // # it under the terms of the GNU Affero General Public License, version 3
5 5 // # (only), as published by the Free Software Foundation.
6 6 // #
7 7 // # This program is distributed in the hope that it will be useful,
8 8 // # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 9 // # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 10 // # GNU General Public License for more details.
11 11 // #
12 12 // # You should have received a copy of the GNU Affero General Public License
13 13 // # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 14 // #
15 15 // # This program is dual-licensed. If you wish to learn more about the
16 16 // # RhodeCode Enterprise Edition, including its added features, Support services,
17 17 // # and proprietary license terms, please see https://rhodecode.com/licenses/
18 18
19 19 /**
20 20 * Pull request reviewers
21 21 */
22 22 var removeReviewMember = function(reviewer_id, mark_delete){
23 23 var reviewer = $('#reviewer_{0}'.format(reviewer_id));
24 24
25 25 if(typeof(mark_delete) === undefined){
26 26 mark_delete = false;
27 27 }
28 28
29 29 if(mark_delete === true){
30 30 if (reviewer){
31 31 // mark as to-remove
32 32 var obj = $('#reviewer_{0}_name'.format(reviewer_id));
33 33 obj.addClass('to-delete');
34 34 // now delete the input
35 35 $('#reviewer_{0} input'.format(reviewer_id)).remove();
36 36 }
37 37 }
38 38 else{
39 39 $('#reviewer_{0}'.format(reviewer_id)).remove();
40 40 }
41 41 };
42 42
43 43 var addReviewMember = function(id, fname, lname, nname, gravatar_link, reasons) {
44 44 var members = $('#review_members').get(0);
45 45 var reasons_html = '';
46 46 var reasons_inputs = '';
47 47 var reasons = reasons || [];
48 48 if (reasons) {
49 49 for (var i = 0; i < reasons.length; i++) {
50 50 reasons_html += '<div class="reviewer_reason">- {0}</div>'.format(reasons[i]);
51 51 reasons_inputs += '<input type="hidden" name="reason" value="' + escapeHtml(reasons[i]) + '">';
52 52 }
53 53 }
54 54 var tmpl = '<li id="reviewer_{2}">'+
55 55 '<input type="hidden" name="__start__" value="reviewer:mapping">'+
56 56 '<div class="reviewer_status">'+
57 57 '<div class="flag_status not_reviewed pull-left reviewer_member_status"></div>'+
58 58 '</div>'+
59 59 '<img alt="gravatar" class="gravatar" src="{0}"/>'+
60 60 '<span class="reviewer_name user">{1}</span>'+
61 61 reasons_html +
62 62 '<input type="hidden" name="user_id" value="{2}">'+
63 63 '<input type="hidden" name="__start__" value="reasons:sequence">'+
64 64 '{3}'+
65 65 '<input type="hidden" name="__end__" value="reasons:sequence">'+
66 66 '<div class="reviewer_member_remove action_button" onclick="removeReviewMember({2})">' +
67 67 '<i class="icon-remove-sign"></i>'+
68 68 '</div>'+
69 69 '</div>'+
70 70 '<input type="hidden" name="__end__" value="reviewer:mapping">'+
71 71 '</li>' ;
72 72
73 73 var displayname = "{0} ({1} {2})".format(
74 74 nname, escapeHtml(fname), escapeHtml(lname));
75 75 var element = tmpl.format(gravatar_link,displayname,id,reasons_inputs);
76 76 // check if we don't have this ID already in
77 77 var ids = [];
78 78 var _els = $('#review_members li').toArray();
79 79 for (el in _els){
80 80 ids.push(_els[el].id)
81 81 }
82 82 if(ids.indexOf('reviewer_'+id) == -1){
83 83 // only add if it's not there
84 84 members.innerHTML += element;
85 85 }
86 86
87 87 };
88 88
89 89 var _updatePullRequest = function(repo_name, pull_request_id, postData) {
90 90 var url = pyroutes.url(
91 91 'pullrequest_update',
92 92 {"repo_name": repo_name, "pull_request_id": pull_request_id});
93 93 if (typeof postData === 'string' ) {
94 94 postData += '&csrf_token=' + CSRF_TOKEN;
95 95 } else {
96 96 postData.csrf_token = CSRF_TOKEN;
97 97 }
98 98 var success = function(o) {
99 99 window.location.reload();
100 100 };
101 101 ajaxPOST(url, postData, success);
102 102 };
103 103
104 104 var updateReviewers = function(reviewers_ids, repo_name, pull_request_id){
105 105 if (reviewers_ids === undefined){
106 106 var postData = '_method=put&' + $('#reviewers input').serialize();
107 107 _updatePullRequest(repo_name, pull_request_id, postData);
108 108 }
109 109 };
110 110
111 111 /**
112 112 * PULL REQUEST reject & close
113 113 */
114 114 var closePullRequest = function(repo_name, pull_request_id) {
115 115 var postData = {
116 116 '_method': 'put',
117 117 'close_pull_request': true};
118 118 _updatePullRequest(repo_name, pull_request_id, postData);
119 119 };
120 120
121 121 /**
122 122 * PULL REQUEST update commits
123 123 */
124 124 var updateCommits = function(repo_name, pull_request_id) {
125 125 var postData = {
126 126 '_method': 'put',
127 127 'update_commits': true};
128 128 _updatePullRequest(repo_name, pull_request_id, postData);
129 129 };
130 130
131 131
132 132 /**
133 133 * PULL REQUEST edit info
134 134 */
135 135 var editPullRequest = function(repo_name, pull_request_id, title, description) {
136 136 var url = pyroutes.url(
137 137 'pullrequest_update',
138 138 {"repo_name": repo_name, "pull_request_id": pull_request_id});
139 139
140 140 var postData = {
141 141 '_method': 'put',
142 142 'title': title,
143 143 'description': description,
144 144 'edit_pull_request': true,
145 145 'csrf_token': CSRF_TOKEN
146 146 };
147 147 var success = function(o) {
148 148 window.location.reload();
149 149 };
150 150 ajaxPOST(url, postData, success);
151 151 };
152 152
153 153 var initPullRequestsCodeMirror = function (textAreaId) {
154 154 var ta = $(textAreaId).get(0);
155 155 var initialHeight = '100px';
156 156
157 157 // default options
158 158 var codeMirrorOptions = {
159 159 mode: "text",
160 160 lineNumbers: false,
161 161 indentUnit: 4,
162 162 theme: 'rc-input'
163 163 };
164 164
165 165 var codeMirrorInstance = CodeMirror.fromTextArea(ta, codeMirrorOptions);
166 166 // marker for manually set description
167 167 codeMirrorInstance._userDefinedDesc = false;
168 168 codeMirrorInstance.setSize(null, initialHeight);
169 169 codeMirrorInstance.on("change", function(instance, changeObj) {
170 170 var height = initialHeight;
171 171 var lines = instance.lineCount();
172 172 if (lines > 6 && lines < 20) {
173 173 height = "auto"
174 174 }
175 175 else if (lines >= 20) {
176 176 height = 20 * 15;
177 177 }
178 178 instance.setSize(null, height);
179 179
180 180 // detect if the change was trigger by auto desc, or user input
181 181 changeOrigin = changeObj.origin;
182 182
183 183 if (changeOrigin === "setValue") {
184 184 cmLog.debug('Change triggered by setValue');
185 185 }
186 186 else {
187 187 cmLog.debug('user triggered change !');
188 188 // set special marker to indicate user has created an input.
189 189 instance._userDefinedDesc = true;
190 190 }
191 191
192 192 });
193 193
194 194 return codeMirrorInstance
195 195 };
196 196
197 197 /**
198 198 * Reviewer autocomplete
199 199 */
200 200 var ReviewerAutoComplete = function(input_id) {
201 201 $('#'+input_id).autocomplete({
202 202 serviceUrl: pyroutes.url('user_autocomplete_data'),
203 203 minChars:2,
204 204 maxHeight:400,
205 205 deferRequestBy: 300, //miliseconds
206 206 showNoSuggestionNotice: true,
207 207 tabDisabled: true,
208 208 autoSelectFirst: true,
209 209 formatResult: autocompleteFormatResult,
210 210 lookupFilter: autocompleteFilterResult,
211 211 onSelect: function(suggestion, data){
212 var msg = _gettext('added manually by "{0}"');
213 var reasons = [msg.format(templateContext.rhodecode_user.username)];
212 214 addReviewMember(data.id, data.first_name, data.last_name,
213 data.username, data.icon_link);
215 data.username, data.icon_link, reasons);
214 216 $('#'+input_id).val('');
215 217 }
216 218 });
217 219 };
@@ -1,173 +1,175 b''
1 1 ## -*- coding: utf-8 -*-
2 2 <!DOCTYPE html>
3 3
4 4 <%
5 5 c.template_context['repo_name'] = getattr(c, 'repo_name', '')
6 6
7 7 if hasattr(c, 'rhodecode_db_repo'):
8 8 c.template_context['repo_type'] = c.rhodecode_db_repo.repo_type
9 9 c.template_context['repo_landing_commit'] = c.rhodecode_db_repo.landing_rev[1]
10 10
11 11 if getattr(c, 'rhodecode_user', None) and c.rhodecode_user.user_id:
12 12 c.template_context['rhodecode_user']['username'] = c.rhodecode_user.username
13 13 c.template_context['rhodecode_user']['email'] = c.rhodecode_user.email
14 14 c.template_context['rhodecode_user']['notification_status'] = c.rhodecode_user.get_instance().user_data.get('notification_status', True)
15 c.template_context['rhodecode_user']['first_name'] = c.rhodecode_user.name
16 c.template_context['rhodecode_user']['last_name'] = c.rhodecode_user.lastname
15 17
16 18 c.template_context['visual']['default_renderer'] = h.get_visual_attr(c, 'default_renderer')
17 19 %>
18 20 <html xmlns="http://www.w3.org/1999/xhtml">
19 21 <head>
20 22 <script src="${h.asset('js/vendors/webcomponentsjs/webcomponents-lite.min.js', ver=c.rhodecode_version_hash)}"></script>
21 23 <link rel="import" href="${h.asset('js/rhodecode-components.html', ver=c.rhodecode_version_hash)}">
22 24 <title>${self.title()}</title>
23 25 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
24 26 <%def name="robots()">
25 27 <meta name="robots" content="index, nofollow"/>
26 28 </%def>
27 29 ${self.robots()}
28 30 <link rel="icon" href="${h.asset('images/favicon.ico', ver=c.rhodecode_version_hash)}" sizes="16x16 32x32" type="image/png" />
29 31
30 32 ## CSS definitions
31 33 <%def name="css()">
32 34 <link rel="stylesheet" type="text/css" href="${h.asset('css/style.css', ver=c.rhodecode_version_hash)}" media="screen"/>
33 35 <!--[if lt IE 9]>
34 36 <link rel="stylesheet" type="text/css" href="${h.asset('css/ie.css', ver=c.rhodecode_version_hash)}" media="screen"/>
35 37 <![endif]-->
36 38 ## EXTRA FOR CSS
37 39 ${self.css_extra()}
38 40 </%def>
39 41 ## CSS EXTRA - optionally inject some extra CSS stuff needed for specific websites
40 42 <%def name="css_extra()">
41 43 </%def>
42 44
43 45 ${self.css()}
44 46
45 47 ## JAVASCRIPT
46 48 <%def name="js()">
47 49 <script>
48 50 // setup Polymer options
49 51 window.Polymer = {lazyRegister: true, dom: 'shadow'};
50 52
51 53 // Load webcomponentsjs polyfill if browser does not support native Web Components
52 54 (function() {
53 55 'use strict';
54 56 var onload = function() {
55 57 // For native Imports, manually fire WebComponentsReady so user code
56 58 // can use the same code path for native and polyfill'd imports.
57 59 if (!window.HTMLImports) {
58 60 document.dispatchEvent(
59 61 new CustomEvent('WebComponentsReady', {bubbles: true})
60 62 );
61 63 }
62 64 };
63 65 var webComponentsSupported = (
64 66 'registerElement' in document
65 67 && 'import' in document.createElement('link')
66 68 && 'content' in document.createElement('template')
67 69 );
68 70 if (!webComponentsSupported) {
69 71 } else {
70 72 onload();
71 73 }
72 74 })();
73 75 </script>
74 76
75 77 <script src="${h.asset('js/rhodecode/i18n/%s.js' % c.language, ver=c.rhodecode_version_hash)}"></script>
76 78 <script type="text/javascript">
77 79 // register templateContext to pass template variables to JS
78 80 var templateContext = ${h.json.dumps(c.template_context)|n};
79 81
80 82 var REPO_NAME = "${getattr(c, 'repo_name', '')}";
81 83 %if hasattr(c, 'rhodecode_db_repo'):
82 84 var REPO_LANDING_REV = '${c.rhodecode_db_repo.landing_rev[1]}';
83 85 var REPO_TYPE = '${c.rhodecode_db_repo.repo_type}';
84 86 %else:
85 87 var REPO_LANDING_REV = '';
86 88 var REPO_TYPE = '';
87 89 %endif
88 90 var APPLICATION_URL = "${h.url('home').rstrip('/')}";
89 91 var ASSET_URL = "${h.asset('')}";
90 92 var DEFAULT_RENDERER = "${h.get_visual_attr(c, 'default_renderer')}";
91 93 var CSRF_TOKEN = "${getattr(c, 'csrf_token', '')}";
92 94 % if getattr(c, 'rhodecode_user', None):
93 95 var USER = {name:'${c.rhodecode_user.username}'};
94 96 % else:
95 97 var USER = {name:null};
96 98 % endif
97 99
98 100 var APPENLIGHT = {
99 101 enabled: ${'true' if getattr(c, 'appenlight_enabled', False) else 'false'},
100 102 key: '${getattr(c, "appenlight_api_public_key", "")}',
101 103 % if getattr(c, 'appenlight_server_url', None):
102 104 serverUrl: '${getattr(c, "appenlight_server_url", "")}',
103 105 % endif
104 106 requestInfo: {
105 107 % if getattr(c, 'rhodecode_user', None):
106 108 ip: '${c.rhodecode_user.ip_addr}',
107 109 username: '${c.rhodecode_user.username}'
108 110 % endif
109 111 },
110 112 tags: {
111 113 rhodecode_version: '${c.rhodecode_version}',
112 114 rhodecode_edition: '${c.rhodecode_edition}'
113 115 }
114 116 };
115 117 </script>
116 118 <%include file="/base/plugins_base.html"/>
117 119 <!--[if lt IE 9]>
118 120 <script language="javascript" type="text/javascript" src="${h.asset('js/excanvas.min.js')}"></script>
119 121 <![endif]-->
120 122 <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script>
121 123 <script> var alertMessagePayloads = ${h.flash.json_alerts()|n}; </script>
122 124 ## avoide escaping the %N
123 125 <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode-components.js', ver=c.rhodecode_version_hash)}"></script>
124 126 <script>CodeMirror.modeURL = "${h.asset('') + 'js/mode/%N/%N.js?ver='+c.rhodecode_version_hash}";</script>
125 127
126 128
127 129 ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates
128 130 ${self.js_extra()}
129 131
130 132 <script type="text/javascript">
131 133 $(document).ready(function(){
132 134 show_more_event();
133 135 timeagoActivate();
134 136 })
135 137 </script>
136 138
137 139 </%def>
138 140
139 141 ## JAVASCRIPT EXTRA - optionally inject some extra JS for specificed templates
140 142 <%def name="js_extra()"></%def>
141 143 ${self.js()}
142 144
143 145 <%def name="head_extra()"></%def>
144 146 ${self.head_extra()}
145 147 ## extra stuff
146 148 %if c.pre_code:
147 149 ${c.pre_code|n}
148 150 %endif
149 151 </head>
150 152 <body id="body">
151 153 <noscript>
152 154 <div class="noscript-error">
153 155 ${_('Please enable JavaScript to use RhodeCode Enterprise')}
154 156 </div>
155 157 </noscript>
156 158 ## IE hacks
157 159 <!--[if IE 7]>
158 160 <script>$(document.body).addClass('ie7')</script>
159 161 <![endif]-->
160 162 <!--[if IE 8]>
161 163 <script>$(document.body).addClass('ie8')</script>
162 164 <![endif]-->
163 165 <!--[if IE 9]>
164 166 <script>$(document.body).addClass('ie9')</script>
165 167 <![endif]-->
166 168
167 169 ${next.body()}
168 170 %if c.post_code:
169 171 ${c.post_code|n}
170 172 %endif
171 173 <rhodecode-app></rhodecode-app>
172 174 </body>
173 175 </html>
General Comments 0
You need to be logged in to leave comments. Login now