-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathIssueCreator.cpp
275 lines (209 loc) · 6.31 KB
/
IssueCreator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#include "IssueCreator.h"
#include "IssueSelector.h"
#include "logging.h"
#include <QSortFilterProxyModel>
using namespace qtredmine;
using namespace redtimer;
using namespace std;
IssueCreator::IssueCreator( SimpleRedmineClient* redmine, QQuickView* parent )
: Window( "qrc:/IssueCreator.qml", parent ),
redmine_( redmine )
{
ENTER();
// Issue selector window initialisation
setResizeMode( QQuickView::SizeRootObjectToView );
setModality( Qt::ApplicationModal );
setFlags( Qt::Dialog );
setTitle( "Issue Creator" );
// Load projects
QSortFilterProxyModel* projectProxyModel = new QSortFilterProxyModel();
projectProxyModel->setSourceModel( &projectModel_ );
projectProxyModel->setSortRole( SimpleModel::SimpleRoles::IdRole );
ctx_->setContextProperty( "projectModel", projectProxyModel );
loadProjects();
// Load trackers
QSortFilterProxyModel* trackerProxyModel = new QSortFilterProxyModel();
trackerProxyModel->setSourceModel( &trackerModel_ );
trackerProxyModel->setSortRole( SimpleModel::SimpleRoles::IdRole );
ctx_->setContextProperty( "trackerModel", trackerProxyModel );
loadTrackers();
loadCurrentUser();
// Connect the project selected signal to the projectSelected slot
connect( qml("project"), SIGNAL(activated(int)), this, SLOT(projectSelected(int)) );
// Connect the tracker selected signal to the trackerSelected slot
connect( qml("tracker"), SIGNAL(activated(int)), this, SLOT(trackerSelected(int)) );
// Connect the issue selector button
connect( qml("selectParentIssue"), SIGNAL(clicked()), this, SLOT(selectParentIssue()) );
// Connect the create button clicked signal to the save slot
connect( qml("create"), SIGNAL(clicked()), this, SLOT(save()) );
// Connect the cancel button clicked signal to the close slot
connect( qml("cancel"), SIGNAL(clicked()), this, SLOT(closeWin()) );
// Connect the closed signal to the close slot
connect( this, &Window::closed, [=](){ closeWin(); } );
RETURN();
}
IssueCreator::~IssueCreator()
{
ENTER();
RETURN();
}
void
IssueCreator::closeWin()
{
ENTER();
if( isVisible() )
{
DEBUG() << "Closing issue creator window";
if( cancelOnClose_ )
cancelled();
close();
}
RETURN();
}
void
IssueCreator::display()
{
ENTER();
if( !isVisible() )
{
DEBUG() << "Displaying issue creator window";
show();
}
RETURN();
}
void
IssueCreator::loadCurrentUser()
{
ENTER();
redmine_->retrieveCurrentUser( [&]( User user )
{
ENTER();
currentUserId_ = user.id;
RETURN();
} );
RETURN();
}
void
IssueCreator::loadProjects()
{
ENTER();
redmine_->retrieveProjects( [&]( Projects projects )
{
ENTER();
projectModel_.clear();
projectModel_.push_back( SimpleItem(NULL_ID, "Choose project") );
for( const auto& project : projects )
projectModel_.push_back( SimpleItem(project) );
qml("project")->setProperty( "currentIndex", -1 );
qml("project")->setProperty( "currentIndex", 0 );
RETURN();
},
QString("limit=100") );
RETURN();
}
void
IssueCreator::loadTrackers()
{
ENTER();
redmine_->retrieveTrackers( [&]( Trackers trackers )
{
ENTER();
trackerModel_.clear();
trackerModel_.push_back( SimpleItem(NULL_ID, "Choose tracker") );
for( const auto& tracker : trackers )
trackerModel_.push_back( SimpleItem(tracker) );
qml("tracker")->setProperty( "currentIndex", -1 );
qml("tracker")->setProperty( "currentIndex", 0 );
RETURN();
} );
RETURN();
}
void
IssueCreator::projectSelected( int index )
{
ENTER();
projectId_ = projectModel_.at(index).id();
DEBUG()(index)(projectId_);
RETURN();
}
void
IssueCreator::save()
{
ENTER();
if( projectId_ == NULL_ID )
{
message( "Please select a project", QtCriticalMsg );
RETURN();
}
if( trackerId_ == NULL_ID )
{
message( "Please select a tracker", QtCriticalMsg );
RETURN();
}
if( qml("subject")->property("text").toString().isEmpty() )
{
message( "Please specify a subject", QtCriticalMsg );
RETURN();
}
cancelOnClose_ = false;
Issue issue;
issue.project.id = projectId_;
issue.tracker.id = trackerId_;
issue.assignedTo.id = currentUserId_;
if( !qml("parentIssue")->property("text").toString().isEmpty() )
issue.parentId = qml("parentIssue")->property("text").toInt();
if( !qml("parentIssue")->property("estimatedTime").toString().isEmpty() )
issue.estimatedHours = qml("estimatedTime")->property("text").toDouble();
issue.subject = qml("subject")->property("text").toString();
issue.description = qml("description")->property("text").toString();
redmine_->sendIssue( issue, [=](bool success, int id, RedmineError errorCode, QStringList errors)
{
ENTER()(success)(id)(errorCode)(errors);
if( !success )
{
cancelOnClose_ = true;
QString errorMsg = tr( "Could not create issue." );
for( const auto& error : errors )
errorMsg.append("\n").append(error);
message( errorMsg, QtCriticalMsg );
RETURN();
}
message( tr("New issue created with ID %1").arg(id) );
created( id );
closeWin();
RETURN();
} );
RETURN();
}
void
IssueCreator::selectParentIssue()
{
// Issue selector initialisation
IssueSelector* issueSelector = new IssueSelector( redmine_ );
issueSelector->setTransientParent( this );
if( projectId_ != NULL_ID )
issueSelector->setProjectId( projectId_ );
issueSelector->display();
// Connect the issue selected signal to the setIssue slot
connect( issueSelector, &IssueSelector::selected, [=](int issueId)
{
qml("parentIssue")->setProperty( "text", issueId );
issueSelector->close();
} );
}
void
IssueCreator::setParentIssueId( int id )
{
ENTER();
if( id != NULL_ID )
qml("parentIssue")->setProperty( "text", id );
RETURN();
}
void
IssueCreator::trackerSelected( int index )
{
ENTER();
trackerId_ = trackerModel_.at(index).id();
DEBUG()(index)(trackerId_);
RETURN();
}