VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testmanager/htdocs/js/vcsrevisions.js@ 98103

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.8 KB
Line 
1/* $Id: vcsrevisions.js 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * Common JavaScript functions
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/**
39 * @internal.
40 */
41function vcsRevisionFormatDate(tsDate)
42{
43 /*return tsDate.toLocaleDateString();*/
44 return tsDate.toISOString().split('T')[0];
45}
46
47/**
48 * @internal.
49 */
50function vcsRevisionFormatTime(tsDate)
51{
52 return formatTimeHHMM(tsDate, true /*fNbsp*/);
53}
54
55/**
56 * Called 'onclick' for the link/button used to show the detailed VCS
57 * revisions.
58 * @internal.
59 */
60function vcsRevisionShowDetails(oElmSource)
61{
62 document.getElementById('vcsrevisions-detailed').style.display = 'block';
63 document.getElementById('vcsrevisions-brief').style.display = 'none';
64 oElmSource.style.display = 'none';
65 return false;
66}
67
68/**
69 * Called when we've got the revision data.
70 * @internal
71 */
72function vcsRevisionsRender(sTestMgr, oElmDst, sBugTracker, oRestReq, sUrl)
73{
74 console.log('vcsRevisionsRender: status=' + oRestReq.status + ' readyState=' + oRestReq.readyState + ' url=' + sUrl);
75 if (oRestReq.readyState != oRestReq.DONE)
76 {
77 oElmDst.innerHTML = '<p>' + oRestReq.readyState + '</p>';
78 return true;
79 }
80
81
82 /*
83 * Check the result and translate it to a javascript object (oResp).
84 */
85 var oResp = null;
86 var sHtml;
87 if (oRestReq.status != 200)
88 {
89 /** @todo figure why this doesn't work (sPath to something random). */
90 var sMsg = oRestReq.getResponseHeader('tm-error-message');
91 console.log('vcsRevisionsRender: status=' + oRestReq.status + ' readyState=' + oRestReq.readyState + ' url=' + sUrl + ' msg=' + sMsg);
92 sHtml = '<p>error: status=' + oRestReq.status + 'readyState=' + oRestReq.readyState + ' url=' + sUrl;
93 if (sMsg)
94 sHtml += ' msg=' + sMsg;
95 sHtml += '</p>';
96 }
97 else
98 {
99 try
100 {
101 oResp = JSON.parse(oRestReq.responseText);
102 }
103 catch (oEx)
104 {
105 console.log('JSON.parse threw: ' + oEx.toString());
106 console.log(oRestReq.responseText);
107 sHtml = '<p>error: JSON.parse threw: ' + oEx.toString() + '</p>';
108 }
109 }
110
111 /*
112 * Do the rendering.
113 */
114 if (oResp)
115 {
116 if (oResp.cCommits == 0)
117 {
118 sHtml = '<p>None.</p>';
119 }
120 else
121 {
122 var aoCommits = oResp.aoCommits;
123 var cCommits = oResp.aoCommits.length;
124 var i;
125
126 sHtml = '';
127 /*sHtml = '<a href="#" onclick="return vcsRevisionShowDetails(this);" class="vcsrevisions-show-details">Show full VCS details...</a>\n';*/
128 /*sHtml = '<button onclick="vcsRevisionShowDetails(this);" class="vcsrevisions-show-details">Show full VCS details...</button>\n';*/
129
130 /* Brief view (the default): */
131 sHtml += '<p id="vcsrevisions-brief">';
132 for (i = 0; i < cCommits; i++)
133 {
134 var oCommit = aoCommits[i];
135 var sUrl = oResp.sTracChangesetUrlFmt.replace('%(sRepository)s', oCommit.sRepository).replace('%(iRevision)s', oCommit.iRevision.toString());
136 var sTitle = oCommit.sAuthor + ': ' + oCommit.sMessage;
137 sHtml += ' <a href="' + escapeElem(sUrl) + '" title="' + escapeElem(sTitle) + '">r' + oCommit.iRevision + '</a> \n';
138 }
139 sHtml += '</p>';
140 sHtml += '<a href="#" onclick="return vcsRevisionShowDetails(this);" class="vcsrevisions-show-details-bottom">Show full VCS details...</a>\n';
141
142 /* Details view: */
143 sHtml += '<div id="vcsrevisions-detailed" style="display:none;">\n';
144 var iCurDay = null;
145 if (0)
146 {
147 /* Changelog variant: */
148 for (i = 0; i < cCommits; i++)
149 {
150 var oCommit = aoCommits[i];
151 var tsCreated = parseIsoTimestamp(oCommit.tsCreated);
152 var sUrl = oResp.sTracChangesetUrlFmt.replace('%(sRepository)s', oCommit.sRepository).replace('%(iRevision)s', oCommit.iRevision.toString());
153 var iCommitDay = Math.floor((tsCreated.getTime() + tsCreated.getTimezoneOffset()) / (24 * 60 * 60 * 1000));
154 if (iCurDay === null || iCurDay != iCommitDay)
155 {
156 if (iCurDay !== null)
157 sHtml += ' </dl>\n';
158 iCurDay = iCommitDay;
159 sHtml += ' <h3>' + vcsRevisionFormatDate(tsCreated) + ' ' + g_kasDaysOfTheWeek[tsCreated.getDay()] + '</h3>\n';
160 sHtml += ' <dl>\n';
161 }
162
163 sHtml += ' <dt id="r' + oCommit.iRevision + '">';
164 sHtml += '<a href="' + oResp.sTracChangesetUrlFmt.replace('%(iRevision)s', oCommit.iRevision.toString()) + '">';
165 /*sHtml += '<span class="vcsrevisions-time">' + escapeElem(vcsRevisionFormatTime(tsCreated)) + '</span>'
166 sHtml += ' Changeset <span class="vcsrevisions-rev">r' + oCommit.iRevision + '</span>';
167 sHtml += ' by <span class="vcsrevisions-author">' + escapeElem(oCommit.sAuthor) + '</span>'; */
168 sHtml += '<span class="vcsrevisions-time">' + escapeElem(vcsRevisionFormatTime(tsCreated)) + '</span>';
169 sHtml += ' - <span class="vcsrevisions-rev">r' + oCommit.iRevision + '</span>';
170 sHtml += ' - <span class="vcsrevisions-author">' + escapeElem(oCommit.sAuthor) + '</span>';
171 sHtml += '</a></dt>\n';
172 sHtml += ' <dd>' + escapeElem(oCommit.sMessage) + '</dd>\n';
173 }
174
175 if (iCurDay !== null)
176 sHtml += ' </dl>\n';
177 }
178 else
179 { /* TABLE variant: */
180 sHtml += '<table class="vcsrevisions-table">';
181 var iAlt = 0;
182 for (i = 0; i < cCommits; i++)
183 {
184 var oCommit = aoCommits[i];
185 var tsCreated = parseIsoTimestamp(oCommit.tsCreated);
186 var sUrl = oResp.sTracChangesetUrlFmt.replace('%(sRepository)s', oCommit.sRepository).replace('%(iRevision)s', oCommit.iRevision.toString());
187 var iCommitDay = Math.floor((tsCreated.getTime() + tsCreated.getTimezoneOffset()) / (24 * 60 * 60 * 1000));
188 if (iCurDay === null || iCurDay != iCommitDay)
189 {
190 iCurDay = iCommitDay;
191 sHtml += '<tr id="r' + oCommit.iRevision + '"><td colspan="4" class="vcsrevisions-tab-date">';
192 sHtml += vcsRevisionFormatDate(tsCreated) + ' ' + g_kasDaysOfTheWeek[tsCreated.getDay()];
193 sHtml += '</td></tr>\n';
194 sHtml += '<tr>';
195 iAlt = 0;
196 }
197 else
198 sHtml += '<tr id="r' + oCommit.iRevision + '">';
199 var sAltCls = '';
200 var sAltClsStmt = '';
201 iAlt += 1;
202 if (iAlt & 1)
203 {
204 sAltCls = ' alt';
205 sAltClsStmt = ' class="alt"';
206 }
207 sHtml += '<td class="vcsrevisions-tab-time'+sAltCls+'"><a href="' + sUrl + '">'
208 + escapeElem(vcsRevisionFormatTime(tsCreated)) + '</a></td>';
209 sHtml += '<td'+sAltClsStmt+'><a href="' + sUrl + '" class="vcsrevisions-rev' + sAltCls + '">r'
210 + oCommit.iRevision + '</a></td>';
211 sHtml += '<td'+sAltClsStmt+'><a href="' + sUrl + '" class="vcsrevisions-author' + sAltCls + '">'
212 + escapeElem(oCommit.sAuthor) + '<a></td>';
213 sHtml += '<td'+sAltClsStmt+'>' + escapeElem(oCommit.sMessage) + '</td></tr>\n';
214 }
215 sHtml += '</table>\n';
216 }
217 sHtml += '</div>\n';
218 }
219 }
220
221 oElmDst.innerHTML = sHtml;
222}
223
224/** Called by the xtracker bugdetails page. */
225function VcsRevisionsLoad(sTestMgr, oElmDst, sBugTracker, lBugNo)
226{
227 oElmDst.innerHTML = '<p>Loading VCS revisions...</p>';
228
229 var sUrl = sTestMgr + 'rest.py?sPath=vcs/bugreferences/' + sBugTracker + '/' + lBugNo;
230 var oRestReq = new XMLHttpRequest();
231 oRestReq.onreadystatechange = function() { vcsRevisionsRender(sTestMgr, oElmDst, sBugTracker, this, sUrl); }
232 oRestReq.open('GET', sUrl);
233 oRestReq.withCredentials = true;
234 /*oRestReq.setRequestHeader('Content-type', 'application/json'); - Causes CORS trouble. */
235 oRestReq.send();
236}
237
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette