1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_GT_UTILS_DASHBOARD_H_
23 #define _U2_GT_UTILS_DASHBOARD_H_
24 
25 #include <QToolButton>
26 
27 #include <U2Designer/Dashboard.h>
28 #include <U2Designer/ExternalToolsDashboardWidget.h>
29 
30 #include "GTGlobals.h"
31 
32 class QTabWidget;
33 
34 namespace U2 {
35 
36 class GTUtilsDashboard {
37 public:
38     enum Tabs { Overview,
39                 Input,
40                 ExternalTools };
41 
42     // Dashboard notification class. Contains the type of notification (info/warning/error), the name of the workflow
43     // element to which the notification relates and the notification message
44     struct Notification {
45         Notification() = delete;  // No default dashboard notification
46 
47         QString type;  // The type of dashboard notification (info/warning/error)
48         QString element;  // The name of workflow element to which the dashboard notification relates
49         QString message;  // The dashboard notification message
50 
51         // Returns the notification as a string
52         QString toString() const;
53     };
54 
55     /** Returns active dashboard or nullptr if not found. */
56     static Dashboard *findDashboard(HI::GUITestOpStatus &os);
57 
58     /** Returns active dashboard. Fails if not found */
59     static Dashboard *getDashboard(HI::GUITestOpStatus &os);
60 
61     /** Returns load-schema button or nullptr if not found. */
62     static QToolButton *findLoadSchemaButton(HI::GUITestOpStatus &os);
63 
64     static QTabWidget *getTabWidget(HI::GUITestOpStatus &os);
65 
66     static const QString getDashboardName(HI::GUITestOpStatus &os, int dashboardNumber);
67 
68     static QStringList getInputFiles(HI::GUITestOpStatus &os);
69 
70     static QStringList getOutputFiles(HI::GUITestOpStatus &os);
71 
72     static void clickOutputFile(HI::GUITestOpStatus &os, const QString &outputFileName);
73 
74     static QString getTabObjectName(Tabs tab);
75 
76     static bool hasNotifications(HI::GUITestOpStatus &os);
77 
78     // Returns a list of dashboard notifications
79     static QList<Notification> getNotifications(HI::GUITestOpStatus &os);
80 
81     // Returns a QString containing all dashboard notifications, splitted by '\n'
82     static QString getJoinedNotificationsString(HI::GUITestOpStatus &os);
83 
84     static void openTab(HI::GUITestOpStatus &os, Tabs tab);
85 
86     static bool hasTab(HI::GUITestOpStatus &os, Tabs tab);
87 
88     // External tools tab
89     static QString getNodeText(HI::GUITestOpStatus &os, const QString &nodeId);
90 
91     static int getChildrenNodesCount(HI::GUITestOpStatus &os, const QString &nodeId);
92 
93     static QList<ExternalToolsTreeNode *> getChildNodes(HI::GUITestOpStatus &os, const QString &nodeId);
94 
95     static QString getChildNodeId(HI::GUITestOpStatus &os, const QString &nodeId, int childIndex);
96     static QString getDescendantNodeId(HI::GUITestOpStatus &os, const QString &nodeId, const QList<int> &childIndexes);
97     static QString getChildWithTextId(HI::GUITestOpStatus &os, const QString &nodeId, const QString &text);  // childrens has to have unique texts
98 
99     static bool hasLimitationMessage(HI::GUITestOpStatus &os, const QString &nodeId);
100     static QString getLimitationMessage(HI::GUITestOpStatus &os, const QString &nodeId);
101     static QString getLogUrlFromNodeLimitationMessage(HI::GUITestOpStatus &os, const QString &nodeId);
102     static QString getLogUrlFromOutputContent(HI::GUITestOpStatus &os, const QString &outputNodeId);
103 
104     static QSize getCopyButtonSize(HI::GUITestOpStatus &os, const QString &toolRunNodeId);
105     static void clickCopyButton(HI::GUITestOpStatus &os, const QString &toolRunNodeId);
106 
107     static bool isNodeVisible(HI::GUITestOpStatus &os, const QString &nodeId);
108     static bool isNodeCollapsed(HI::GUITestOpStatus &os, const QString &nodeId);
109     static void collapseNode(HI::GUITestOpStatus &os, const QString &nodeId);
110     static void expandNode(HI::GUITestOpStatus &os, const QString &nodeId);
111     static void clickNodeTitle(HI::GUITestOpStatus &os, ExternalToolsTreeNode *node);
112 
113     static const QString TREE_ROOT_ID;
114 
115     static QWidget *getCopyButton(HI::GUITestOpStatus &os, const QString &toolRunNodeId);
116     static ExternalToolsDashboardWidget *getExternalToolsWidget(HI::GUITestOpStatus &os);
117     static ExternalToolsTreeNode *getExternalToolNode(HI::GUITestOpStatus &os, const QString &nodeId);
118 
119     /** Returns external tool matched by text on any level. */
120     static ExternalToolsTreeNode *getExternalToolNodeByText(HI::GUITestOpStatus &os, const QString &textPattern, bool isExactMatch = true);
121 
122     /** Returns external tool matched by text with the given parent only. If parent is nullptr - any level is searched. */
123     static ExternalToolsTreeNode *getExternalToolNodeByText(HI::GUITestOpStatus &os, ExternalToolsTreeNode *parent, const QString &textPattern, bool isExactMatch = true);
124 
125     /** Returns list of external tool nodes matched by text with the given parent only. If parent is nullptr - any level is searched. */
126     static QList<ExternalToolsTreeNode *> getExternalToolNodesByText(HI::GUITestOpStatus &os, ExternalToolsTreeNode *parent, const QString &textPattern, bool isExactMatch = true);
127 
128 private:
129     /** The <img> tag with the class attribute is searched for in the |html|. The attribute value is the type of notification. */
130     static QString getNotificationTypeFromHtml(HI::GUITestOpStatus &os, const QString &html);
131 
132     /** Returns text from the (row, column) notification table cell. The (row, column) cell must exist. */
133     static QString getNotificationCellText(HI::GUITestOpStatus &os, const QGridLayout &tableLayout, int row, int col);
134 
135     static const QMap<QString, Tabs> tabMap;
136 };
137 
138 }  // namespace U2
139 
140 #endif  // _U2_GT_UTILS_DASHBOARD_H_
141