1 | /* $Id: vcsrevisions.js 84619 2020-05-30 19:05:40Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Common JavaScript functions
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /** Called when we've got the revision data. */
|
---|
28 | function vcsRevisionsRender(sTestMgr, oElmDst, sBugTracker, oRestReq, sUrl)
|
---|
29 | {
|
---|
30 | console.log('vcsRevisionsRender: status=' + oRestReq.status + ' readyState=' + oRestReq.readyState + ' url=' + sUrl);
|
---|
31 | if (oRestReq.readyState != oRestReq.DONE)
|
---|
32 | {
|
---|
33 | oElmDst.innerHTML = '<p>' + oRestReq.readyState + '</p>';
|
---|
34 | return true;
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | /*
|
---|
39 | * Check the result and translate it to a javascript object (oResp).
|
---|
40 | */
|
---|
41 | var oResp = null;
|
---|
42 | var sHtml;
|
---|
43 | if (oRestReq.status != 200)
|
---|
44 | {
|
---|
45 | /** @todo figure why this doesn't work (sPath to something random). */
|
---|
46 | var sMsg = oRestReq.getResponseHeader('tm-error-message');
|
---|
47 | console.log('vcsRevisionsRender: status=' + oRestReq.status + ' readyState=' + oRestReq.readyState + ' url=' + sUrl + ' msg=' + sMsg);
|
---|
48 | sHtml = '<p>error: status=' + oRestReq.status + 'readyState=' + oRestReq.readyState + ' url=' + sUrl;
|
---|
49 | if (sMsg)
|
---|
50 | sHtml += ' msg=' + sMsg;
|
---|
51 | sHtml += '</p>';
|
---|
52 | }
|
---|
53 | else
|
---|
54 | {
|
---|
55 | try
|
---|
56 | {
|
---|
57 | oResp = JSON.parse(oRestReq.responseText);
|
---|
58 | }
|
---|
59 | catch (oEx)
|
---|
60 | {
|
---|
61 | console.log('JSON.parse threw: ' + oEx.toString());
|
---|
62 | console.log(oRestReq.responseText);
|
---|
63 | sHtml = '<p>error: JSON.parse threw: ' + oEx.toString() + '</p>';
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Do the rendering.
|
---|
69 | */
|
---|
70 | if (oResp)
|
---|
71 | {
|
---|
72 | if (oResp.cCommits == 0)
|
---|
73 | {
|
---|
74 | sHtml = '<p>None.</p>';
|
---|
75 | }
|
---|
76 | else
|
---|
77 | {
|
---|
78 | sHtml = '<p>';
|
---|
79 |
|
---|
80 | var aoCommits = oResp.aoCommits;
|
---|
81 | var cCommits = oResp.aoCommits.length;
|
---|
82 | var i;
|
---|
83 | for (i = 0; i < cCommits; i++)
|
---|
84 | {
|
---|
85 | var oCommit = aoCommits[i];
|
---|
86 | var sUrl = oResp.sTracChangesetUrlFmt.replace('%(sRepository)s', oCommit.sRepository).replace('%(iRevision)s', oCommit.iRevision.toString());
|
---|
87 | var sTitle = oCommit.sAuthor + ': ' + oCommit.sMessage;
|
---|
88 | sHtml += ' <a href="' + escapeElem(sUrl) + '" title="' + escapeElem(sTitle) + '">r' + oCommit.iRevision + '</a> \n';
|
---|
89 | }
|
---|
90 |
|
---|
91 | sHtml += '</p>';
|
---|
92 |
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | oElmDst.innerHTML = sHtml;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /** Called by the xtracker bugdetails page. */
|
---|
100 | function VcsRevisionsLoad(sTestMgr, oElmDst, sBugTracker, lBugNo)
|
---|
101 | {
|
---|
102 | oElmDst.innerHTML = '<p>Loading VCS revisions...</p>';
|
---|
103 |
|
---|
104 | var sUrl = sTestMgr + 'rest.py?sPath=vcs/bugreferences/' + sBugTracker + '/' + lBugNo;
|
---|
105 | var oRestReq = new XMLHttpRequest();
|
---|
106 | oRestReq.onreadystatechange = function() { vcsRevisionsRender(sTestMgr, oElmDst, sBugTracker, this, sUrl); }
|
---|
107 | oRestReq.open('GET', sUrl);
|
---|
108 | oRestReq.withCredentials = true;
|
---|
109 | //oRestReq.setRequestHeader('Content-type', 'application/json');
|
---|
110 | oRestReq.send();
|
---|
111 | }
|
---|
112 |
|
---|