-
Notifications
You must be signed in to change notification settings - Fork 10
/
UploadView.qml
698 lines (598 loc) · 29.8 KB
/
UploadView.qml
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/* Copyright 2021 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.12
import QtQuick.Dialogs 1.3
//------------------------------------------------------------------------------
import ArcGIS.AppFramework 1.0
//------------------------------------------------------------------------------
import "Portal"
import "TilePackage"
import "ProgressIndicator"
import "singletons" as Singletons
//------------------------------------------------------------------------------
Item {
// PROPERTIES //////////////////////////////////////////////////////////////
id: uploadView
property Portal portal
property var currentTPKUrl: null
property bool fileAcceptedForUpload: false
property bool uploading: false
signal uploadStarted()
signal uploadComplete()
// SIGNAL IMPLEMENTATION ///////////////////////////////////////////////////
Component.onCompleted: {
if (calledFromAnotherApp) {
if (dlr.filePath !== null) {
fileInfo.filePath = dlr.filePath
if (fileInfo.exists) {
fileAccepted(dlr.filePath);
}
else {
uploadStatusIndicator.messageType = uploadStatusIndicator.error;
uploadStatusIndicator.message = "The .tpk file does not exist. <a href='%1'>Return to %2</a>".arg(dlr.successCallback).arg(dlr.callingApplication);
uploadStatusIndicator.show();
}
}
}
}
//--------------------------------------------------------------------------
StackView.onActivating: {
mainView.appToolBar.backButtonEnabled = (!calledFromAnotherApp) ? true : false
mainView.appToolBar.backButtonVisible = (!calledFromAnotherApp) ? true : false
mainView.appToolBar.historyButtonEnabled = true;
mainView.appToolBar.settingsButtonEnabled = true;
mainView.appToolBar.toolBarTitleLabel = Singletons.Strings.uploadTilePackage
}
//--------------------------------------------------------------------------
onFileAcceptedForUploadChanged: {
if (fileAcceptedForUpload) {
uploadStatusIndicator.hide();
}
else {
resetProperties();
}
}
//--------------------------------------------------------------------------
onUploadingChanged: {
mainView.appToolBar.enabled = uploading ? false : true;
}
//--------------------------------------------------------------------------
onUploadStarted: {
uploading = true;
uploadStatusIndicator.hide();
}
//--------------------------------------------------------------------------
onUploadComplete: {
uploading = false;
fileAcceptedForUpload = false;
statusWebMercCheck.progressIcon = "";
statusWebMercCheck.progressText = "";
selectedTPKFileName.text = Singletons.Strings.noFileChosen;
tpkUploadDetails.reset();
resetProperties();
}
// UI //////////////////////////////////////////////////////////////////////
Rectangle {
anchors.fill: parent
color: "#eee"
ColumnLayout {
id: uploadTPKViewColumnLayout
anchors.fill: parent
spacing: sf(1)
// MAIN SECTION ////////////////////////////////////////////////////
Rectangle {
Layout.fillWidth: true
Layout.fillHeight: true
clip: true
color: Singletons.Colors.subtleBackground
RowLayout {
id: tpkForm
anchors.fill: parent
spacing: sf(1)
enabled: uploading ? false : true
// DRAG AND DROP AREA //////////////////////////////////////
Rectangle {
Layout.fillHeight: true
Layout.fillWidth: true
color: "#fff"
Rectangle {
color: Singletons.Colors.boldUIElementBackground
anchors.top: parent.top
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.margins: sf(12)
Item {
id: selectTPK
width: sf(200)
height: sf(200)
anchors.centerIn: parent
enabled: fileAcceptedForUpload ? false : true
visible: fileAcceptedForUpload ? false : true
ColumnLayout {
anchors.fill: parent
spacing: 0
Text {
Layout.fillWidth: true
Layout.preferredHeight: selectTPK.height / 3
text: Singletons.Strings.dragTPKFile
color: Singletons.Colors.boldUIElementFontColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pointSize: Singletons.Config.largeFontSizePoint
font.family: defaultFontFamily
}
Text {
Layout.fillWidth: true
Layout.preferredHeight: selectTPK.height / 3
text: Singletons.Strings.or
color: Singletons.Colors.boldUIElementFontColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.family: defaultFontFamily
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: selectTPK.height / 3
color: "transparent"
Button {
id: openFileChooserBtn
anchors.fill: parent
anchors.margins: sf(10)
enabled: uploading ? false : true
background: Rectangle {
anchors.fill: parent
color:Singletons.Config.buttonStates(this.parent)
radius: app.info.properties.mainButtonRadius
border.width: parent.enabled ? app.info.properties.mainButtonBorderWidth : 0
border.color: app.info.properties.mainButtonBorderColor
}
Text {
color: app.info.properties.mainButtonFontColor
anchors.centerIn: parent
textFormat: Text.RichText
text: Singletons.Strings.browseForFile
font.pointSize: Singletons.Config.baseFontSizePoint
font.family: defaultFontFamily
}
onClicked: {
resetProperties();
fileChooser.open();
}
}
}
}
}
Item {
id: selectedTPK
width: sf(200)
height: sf(200)
anchors.centerIn: parent
visible: fileAcceptedForUpload ? true : false
enabled: fileAcceptedForUpload ? true : false
ColumnLayout {
anchors.fill: parent
spacing: 0
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: selectedTPK.height / 4
color: "transparent"
Image {
id: tpkIcon
source: fileAcceptedForUpload ? "images/happy_face.png" : "images/sad_face.png"
height: parent.height
fillMode: Image.PreserveAspectFit
anchors.centerIn: parent
}
}
Text {
id: selectedTPKFileName
Layout.fillWidth: true
Layout.preferredHeight: selectedTPK.height / 4
text: "filename.tpk"
fontSizeMode: Text.Fit
font.family: defaultFontFamily
minimumPointSize: Singletons.Config.smallFontSizePoint
color: Singletons.Colors.boldUIElementFontColor
font.pointSize: Singletons.Config.largeFontSizePoint
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
ProgressIndicator {
id: statusWebMercCheck
Layout.fillWidth: true
Layout.preferredHeight: selectedTPK.height / 4 - 10
statusTextLeftMargin: sf(10)
iconContainerLeftMargin: sf(5)
iconContainerHeight: this.containerHeight - 5
containerHeight: selectedTPK.height / 4 - 10
statusText.horizontalAlignment: Text.AlignHCenter
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: selectedTPK.height / 4
color: "transparent"
Button {
id: changeTPKFileBtn
anchors.fill: parent
anchors.margins: sf(10)
background: Rectangle {
anchors.fill: parent
color: "transparent"
radius: app.info.properties.mainButtonRadius
border.width: 0
border.color: app.info.properties.mainButtonBorderColor
}
Text {
color: app.info.properties.mainButtonBackgroundColor
anchors.centerIn: parent
textFormat: Text.RichText
text: Singletons.Strings.useDifferentFile
font.pointSize: Singletons.Config.baseFontSizePoint
font.family: defaultFontFamily
}
onClicked: {
fileAcceptedForUpload = false;
}
}
}
}
}
DropArea {
id: tpkDropArea
anchors.fill: parent
enabled: uploading ? false : true
onEntered: {
if (isTPKFile(drag.urls.toString())) {
tpkIcon.source = "images/happy_face.png";
} else {
tpkIcon.source = "images/sad_face.png";
}
}
onDropped: {
statusWebMercCheck.visible = false
if (isTPKFile(drop.urls.toString())) {
fileAccepted(AppFramework.resolvedUrl(drop.urls[0]));
} else {
tpkIcon.source = "images/sad_face.png";
selectedTPKFileName.text = Singletons.Strings.tpkFilesOnly;
tpkUploadDetails.tpkTitle = "";
}
}
}
}
}
// FORM DETAILS ////////////////////////////////////////////
Rectangle {
Layout.fillHeight: true
Layout.preferredWidth: sf(350)
color: "#fff"
DetailsForm {
id: tpkUploadDetails
anchors.fill: parent
enabled: uploading ? false : true
uploadOnly: true
exportAndUpload: false
exportPathBuffering: false
}
}
}
// UPLOAD OVERLAY //////////////////////////////////////////////
Rectangle{
id: tpkUploadStatusOverlay
color: Singletons.Colors.subtleBackground
opacity: .9
anchors.fill: parent
visible: uploading ? true : false
}
}
// BOTTOM TASK BAR /////////////////////////////////////////////////
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: sf(60)
color: "#fff"
RowLayout {
anchors.fill: parent
spacing: 0
Rectangle {
color: "#fff"
Layout.fillHeight: true
Layout.fillWidth: true
Rectangle{
id: uploadStatusContainer
anchors.fill: parent
anchors.margins: sf(10)
StatusIndicator{
id: uploadStatusIndicator
anchors.fill: parent
containerHeight: parent.height
hideAutomatically: true
showDismissButton: true
}
}
}
Rectangle {
Layout.fillHeight: true
Layout.preferredWidth: sf(140)
color: "#fff"
Button {
id: uploadTPKBtn
enabled: (!fileAcceptedForUpload || uploading) ? false : true
anchors.fill: parent
anchors.margins: sf(10)
background: Rectangle {
anchors.fill: parent
color: Singletons.Config.buttonStates(this.parent)
radius: app.info.properties.mainButtonRadius
border.width: parent.enabled ? app.info.properties.mainButtonBorderWidth : 0
border.color: app.info.properties.mainButtonBorderColor
}
RowLayout{
spacing:0
anchors.fill: parent
Text {
id: uploadTPKBtnText
color: app.info.properties.mainButtonFontColor
Layout.fillHeight: true
Layout.fillWidth: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
textFormat: Text.RichText
text: uploading ? ( tpkPackage.aborted ? Singletons.Strings.cancelling : Singletons.Strings.uploading ): Singletons.Strings.upload
font.pointSize: Singletons.Config.baseFontSizePoint
font.family: defaultFontFamily
}
ProgressIndicator{
id:statusUploadStatus
visible: uploading ? true : false
Layout.preferredWidth: parent.height
containerHeight: parent.height
progressIndicatorBackground: "transparent"
iconContainerBackground: "transparent"
statusText.visible: false
progressIcon: uploading ? statusUploadStatus.working : ""
progressText: uploading ? "" : ""
}
}
onClicked: {
if (currentTPKUrl !== null) {
uploadStarted();
tpkPackage.upload(currentTPKUrl, tpkUploadDetails.tpkTitle, tpkUploadDetails.tpkDescription);
}
}
}
}
Rectangle {
Layout.fillHeight: true
Layout.preferredWidth: sf(140)
color: "#fff"
visible: uploading
Button {
id: uploadCancelBtn
anchors.fill: parent
anchors.margins: sf(10)
enabled: uploading ? (tpkPackage.aborted ? false : true) : false
background: Rectangle {
anchors.fill: parent
color: Singletons.Config.buttonStates(this.parent, "clear")
radius: app.info.properties.mainButtonRadius
border.width: parent.enabled ? app.info.properties.mainButtonBorderWidth : 0
border.color: "#fff"
}
Text {
color: (!tpkPackage.aborted) ? app.info.properties.mainButtonBackgroundColor : "#aaa"
anchors.centerIn: parent
textFormat: Text.RichText
text: Singletons.Strings.cancel
font.pointSize: Singletons.Config.baseFontSizePoint
font.family: defaultFontFamily
}
onClicked: {
tpkPackage.cancel();
}
}
}
}
}
}
}
// COMPONENTS //////////////////////////////////////////////////////////////
FileDialog {
id: fileChooser
title: "Please choose a Tile Package (.tpk)"
selectMultiple: false
nameFilters: ["TPK (*.tpk)"]
modality: Qt.WindowModal
onAccepted: {
fileAccepted(fileChooser.fileUrl);
fileChooser.close();
}
onRejected: {
fileAcceptedForUpload = false;
fileChooser.close();
}
}
//--------------------------------------------------------------------------
FileInfo {
id: fileInfo
}
//--------------------------------------------------------------------------
TilePackageUpload {
id: tpkPackage
portal: uploadView.portal
onSrCheckComplete: {
if (tpkPackage.isWebMercator) {
statusWebMercCheck.progressIcon = statusWebMercCheck.success;
statusWebMercCheck.progressText = Singletons.Strings.webMercator;
} else {
statusWebMercCheck.progressIcon = statusWebMercCheck.failed;
statusWebMercCheck.progressText = Singletons.Strings.notWebMercator;
}
}
onUploadStarted: {
}
onUploadComplete: {
try {
var sql = "INSERT into 'uploads' ";
sql += "(title, transaction_date, description, published_service_url, user) ";
sql += "VALUES(:title, :transaction_date, :description, :published_service_url, :user)"
var params = {
"title": tpkUploadDetails.tpkTitle,
"transaction_date": Date.now(),
"description": ((tpkUploadDetails.tpkDescription !== "") ? tpkUploadDetails.tpkDescription : Singletons.Strings.defaultTPKDesc),
"published_service_url": (portal.owningSystemUrl + "/home/item.html?id=" + id),
"user": portal.user.email
}
appDatabase.write(sql,params);
}
catch (error) {
appMetrics.reportError(error);
}
finally {
if (tpkUploadDetails.currentSharing !== "") {
uploadTPKUpdate.share(id, tpkUploadDetails.currentSharing);
}
else {
uploadStatusIndicator.messageType = uploadStatusIndicator.success;
if(calledFromAnotherApp && dlr.successCallback !== ""){
uploadStatusIndicator.message = "Upload Complete. <a href='%1?isShared=%2&isOnline=%3&itemId=%4'>Return to %5</a>".arg(dlr.successCallback).arg("false").arg("true").arg(id).arg(dlr.callingApplication);
}
else{
uploadStatusIndicator.message = "Upload Complete. <a href=\"" + portal.owningSystemUrl + "/home/item.html?id=" + id + "\">View Online</a>";
}
uploadStatusIndicator.show();
uploadView.uploadComplete();
}
}
}
onUploadCancelled: {
uploadStatusIndicator.messageType = uploadStatusIndicator.info;
uploadStatusIndicator.message = Singletons.Strings.uploadCancelled;
uploadStatusIndicator.show();
uploadView.uploadComplete();
}
onUploadProgress: {
}
onUploadFailed: {
uploadStatusIndicator.messageType = uploadStatusIndicator.error;
if(error.message.indexOf("already exists") > -1){
error.message = Singletons.Strings.tpkWithThatNameAlreadyExistsError;
}
try{
throw new Error(error.message);
}
catch(e){
appMetrics.reportError(e)
}
uploadStatusIndicator.message = Singletons.Strings.uploadFailedError + ": " + error.message;
uploadStatusIndicator.show();
uploadView.uploadComplete();
}
onUploadError: {
uploadStatusIndicator.messageType = uploadStatusIndicator.error;
uploadStatusIndicator.message = Singletons.Strings.uploadFailedError + " Error: " + error;
uploadStatusIndicator.show();
uploadView.uploadComplete();
try{
throw new Error(error);
}
catch(e){
appMetrics.reportError(e)
}
}
}
//--------------------------------------------------------------------------
TilePackageUpdate {
id: uploadTPKUpdate
portal: uploadView.portal
onShared: {
uploadStatusIndicator.messageType = uploadStatusIndicator.success;
if(calledFromAnotherApp && dlr.successCallback !== ""){
uploadStatusIndicator.message = "Upload Complete. <a href='%1?isShared=%2&isOnline=%3&itemId=%4'>Return to %5</a>".arg(dlr.successCallback).arg("true").arg("true").arg(itemId).arg(dlr.callingApplication);
}
else{
uploadStatusIndicator.message = "Upload and Sharing Complete. <a href=\"" + portal.owningSystemUrl + "/home/item.html?id=" + itemId + "\">View Online</a>";
}
uploadStatusIndicator.show();
uploadView.uploadComplete();
}
onUpdated: {}
onError: {
uploadStatusIndicator.messageType = uploadStatusIndicator.error;
if(calledFromAnotherApp && dlr.successCallback !== ""){
uploadStatusIndicator.message = "Upload Complete. Error Sharing. <a href='%1?isShared=%2&isOnline=%3&itemId=%4'>Return to %5</a>".arg(dlr.successCallback).arg("false").arg("true").arg(itemId).arg(dlr.callingApplication);
}
else{
uploadStatusIndicator.message = "Upload Complete. Error Sharing. <a href=\"" + portal.owningSystemUrl + "/home/item.html?id=" + itemId + "\">View Online</a>";
}
uploadStatusIndicator.show();
uploadView.uploadComplete();
}
}
// METHODS /////////////////////////////////////////////////////////////////
function resetProperties() {
currentTPKUrl = null;
}
//--------------------------------------------------------------------------
function uiEntryElementStates(control) {
if (!control.enabled) {
return "#888";
} else {
return Singletons.Colors.formElementBackground;
}
}
//--------------------------------------------------------------------------
function isTPKFile(item) {
var extension = ".tpk"
if ((item.indexOf(extension, item.lastIndexOf('/') + 1)) > -1) {
console.log('is a tpk');
return true;
} else {
console.log('is not a tpk');
return false;
}
}
//--------------------------------------------------------------------------
function extractTPKFileName(item) {
return item.substring(item.lastIndexOf('/') + 1, item.length);
}
//--------------------------------------------------------------------------
function extractDefaultTPKTitle(filename){
var defaultTitle;
if(filename.indexOf("_") > -1){
defaultTitle = filename.substring(0, filename.lastIndexOf("_"));
defaultTitle = defaultTitle.replace(/_/g, " ");
}
else{
defaultTitle = filename.substring(0,30);
}
return defaultTitle;
}
//--------------------------------------------------------------------------
function fileAccepted(fileUrl) {
currentTPKUrl = fileUrl;
fileAcceptedForUpload = true;
selectedTPKFileName.text = extractTPKFileName(fileUrl.toString());
tpkUploadDetails.tpkTitle = extractDefaultTPKTitle(selectedTPKFileName.text);
statusWebMercCheck.progressIcon = statusWebMercCheck.working;
statusWebMercCheck.progressText = Singletons.Strings.checkingSpatialReference;
statusWebMercCheck.visible = true;
tpkPackage.getTPKSpatialReference(currentTPKUrl);
}
}