1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: wuiadminfailurecategory.py 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Test Manager WUI - Failure Categories Web content generator.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
11 |
|
---|
12 | This file is part of VirtualBox base platform packages, as
|
---|
13 | available from https://www.virtualbox.org.
|
---|
14 |
|
---|
15 | This program is free software; you can redistribute it and/or
|
---|
16 | modify it under the terms of the GNU General Public License
|
---|
17 | as published by the Free Software Foundation, in version 3 of the
|
---|
18 | License.
|
---|
19 |
|
---|
20 | This program is distributed in the hope that it will be useful, but
|
---|
21 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
23 | General Public License for more details.
|
---|
24 |
|
---|
25 | You should have received a copy of the GNU General Public License
|
---|
26 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
27 |
|
---|
28 | The contents of this file may alternatively be used under the terms
|
---|
29 | of the Common Development and Distribution License Version 1.0
|
---|
30 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
31 | in the VirtualBox distribution, in which case the provisions of the
|
---|
32 | CDDL are applicable instead of those of the GPL.
|
---|
33 |
|
---|
34 | You may elect to license modified versions of this file under the
|
---|
35 | terms and conditions of either the GPL or the CDDL or both.
|
---|
36 |
|
---|
37 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
38 | """
|
---|
39 | __version__ = "$Revision: 98103 $"
|
---|
40 |
|
---|
41 |
|
---|
42 | # Validation Kit imports.
|
---|
43 | from testmanager.webui.wuicontentbase import WuiFormContentBase, WuiContentBase, WuiListContentBase, WuiTmLink;
|
---|
44 | from testmanager.webui.wuiadminfailurereason import WuiAdminFailureReasonList;
|
---|
45 | from testmanager.core.failurecategory import FailureCategoryData;
|
---|
46 | from testmanager.core.failurereason import FailureReasonLogic;
|
---|
47 |
|
---|
48 |
|
---|
49 | class WuiFailureReasonCategoryLink(WuiTmLink):
|
---|
50 | """ Link to a failure category. """
|
---|
51 | def __init__(self, idFailureCategory, sName = WuiContentBase.ksShortDetailsLink, sTitle = None, fBracketed = None):
|
---|
52 | if fBracketed is None:
|
---|
53 | fBracketed = len(sName) > 2;
|
---|
54 | from testmanager.webui.wuiadmin import WuiAdmin;
|
---|
55 | WuiTmLink.__init__(self, sName = sName,
|
---|
56 | sUrlBase = WuiAdmin.ksScriptName,
|
---|
57 | dParams = { WuiAdmin.ksParamAction: WuiAdmin.ksActionFailureCategoryDetails,
|
---|
58 | FailureCategoryData.ksParam_idFailureCategory: idFailureCategory, },
|
---|
59 | fBracketed = fBracketed,
|
---|
60 | sTitle = sTitle);
|
---|
61 | self.idFailureCategory = idFailureCategory;
|
---|
62 |
|
---|
63 |
|
---|
64 |
|
---|
65 | class WuiFailureCategory(WuiFormContentBase):
|
---|
66 | """
|
---|
67 | WUI Failure Category HTML content generator.
|
---|
68 | """
|
---|
69 |
|
---|
70 | def __init__(self, oData, sMode, oDisp):
|
---|
71 | """
|
---|
72 | Prepare & initialize parent
|
---|
73 | """
|
---|
74 |
|
---|
75 | sTitle = 'Failure Category';
|
---|
76 | if sMode == WuiFormContentBase.ksMode_Add:
|
---|
77 | sTitle = 'Add ' + sTitle;
|
---|
78 | elif sMode == WuiFormContentBase.ksMode_Edit:
|
---|
79 | sTitle = 'Edit ' + sTitle;
|
---|
80 | else:
|
---|
81 | assert sMode == WuiFormContentBase.ksMode_Show;
|
---|
82 |
|
---|
83 | WuiFormContentBase.__init__(self, oData, sMode, 'FailureCategory', oDisp, sTitle);
|
---|
84 |
|
---|
85 | def _populateForm(self, oForm, oData):
|
---|
86 | """
|
---|
87 | Construct an HTML form
|
---|
88 | """
|
---|
89 |
|
---|
90 | oForm.addIntRO (FailureCategoryData.ksParam_idFailureCategory, oData.idFailureCategory, 'Failure Category ID')
|
---|
91 | oForm.addTimestampRO(FailureCategoryData.ksParam_tsEffective, oData.tsEffective, 'Last changed')
|
---|
92 | oForm.addTimestampRO(FailureCategoryData.ksParam_tsExpire, oData.tsExpire, 'Expires (excl)')
|
---|
93 | oForm.addIntRO (FailureCategoryData.ksParam_uidAuthor, oData.uidAuthor, 'Changed by UID')
|
---|
94 | oForm.addText (FailureCategoryData.ksParam_sShort, oData.sShort, 'Short Description')
|
---|
95 | oForm.addText (FailureCategoryData.ksParam_sFull, oData.sFull, 'Full Description')
|
---|
96 |
|
---|
97 | oForm.addSubmit()
|
---|
98 |
|
---|
99 | return True;
|
---|
100 |
|
---|
101 | def _generatePostFormContent(self, oData):
|
---|
102 | """
|
---|
103 | Adds a table with the category members below the form.
|
---|
104 | """
|
---|
105 | if oData.idFailureCategory is not None and oData.idFailureCategory >= 0:
|
---|
106 | oLogic = FailureReasonLogic(self._oDisp.getDb());
|
---|
107 | tsNow = self._oDisp.getNow();
|
---|
108 | cMax = 4096;
|
---|
109 | aoEntries = oLogic.fetchForListingInCategory(0, cMax, tsNow, oData.idFailureCategory)
|
---|
110 | if aoEntries:
|
---|
111 | oList = WuiAdminFailureReasonList(aoEntries, 0, cMax, tsNow, fnDPrint = None, oDisp = self._oDisp);
|
---|
112 | return [ [ 'Members', oList.show(fShowNavigation = False)[1]], ];
|
---|
113 | return [];
|
---|
114 |
|
---|
115 |
|
---|
116 |
|
---|
117 | class WuiFailureCategoryList(WuiListContentBase):
|
---|
118 | """
|
---|
119 | WUI Admin Failure Category Content Generator.
|
---|
120 | """
|
---|
121 |
|
---|
122 | def __init__(self, aoEntries, iPage, cItemsPerPage, tsEffective, fnDPrint, oDisp, aiSelectedSortColumns = None):
|
---|
123 | WuiListContentBase.__init__(self, aoEntries, iPage, cItemsPerPage, tsEffective,
|
---|
124 | sTitle = 'Failure Categories', sId = 'failureCategories',
|
---|
125 | fnDPrint = fnDPrint, oDisp = oDisp, aiSelectedSortColumns = aiSelectedSortColumns);
|
---|
126 |
|
---|
127 | self._asColumnHeaders = ['ID', 'Short Description', 'Full Description', 'Actions' ]
|
---|
128 | self._asColumnAttribs = ['align="right"', 'align="center"', 'align="center"', 'align="center"']
|
---|
129 |
|
---|
130 | def _formatListEntry(self, iEntry):
|
---|
131 | from testmanager.webui.wuiadmin import WuiAdmin
|
---|
132 | oEntry = self._aoEntries[iEntry]
|
---|
133 |
|
---|
134 | aoActions = [
|
---|
135 | WuiTmLink('Details', WuiAdmin.ksScriptName,
|
---|
136 | { WuiAdmin.ksParamAction: WuiAdmin.ksActionFailureCategoryDetails,
|
---|
137 | FailureCategoryData.ksParam_idFailureCategory: oEntry.idFailureCategory }),
|
---|
138 | ];
|
---|
139 | if self._oDisp is None or not self._oDisp.isReadOnlyUser():
|
---|
140 | aoActions += [
|
---|
141 | WuiTmLink('Modify', WuiAdmin.ksScriptName,
|
---|
142 | { WuiAdmin.ksParamAction: WuiAdmin.ksActionFailureCategoryEdit,
|
---|
143 | FailureCategoryData.ksParam_idFailureCategory: oEntry.idFailureCategory }),
|
---|
144 | WuiTmLink('Remove', WuiAdmin.ksScriptName,
|
---|
145 | { WuiAdmin.ksParamAction: WuiAdmin.ksActionFailureCategoryDoRemove,
|
---|
146 | FailureCategoryData.ksParam_idFailureCategory: oEntry.idFailureCategory },
|
---|
147 | sConfirm = 'Do you really want to remove failure cateogry #%d?' % (oEntry.idFailureCategory,)),
|
---|
148 | ]
|
---|
149 |
|
---|
150 | return [ oEntry.idFailureCategory,
|
---|
151 | oEntry.sShort,
|
---|
152 | oEntry.sFull,
|
---|
153 | aoActions,
|
---|
154 | ];
|
---|
155 |
|
---|