514
514
@save-changes =" onSave"
515
515
@save-status =" updateSaveStatus"
516
516
@refresh-config =" refreshConfig"
517
+ @export-product =" exportProduct"
517
518
ref =" mainEditor"
518
519
>
519
520
<!-- Metadata editing modal inside the editor -->
@@ -591,6 +592,7 @@ import { useUserStore } from '../stores/userStore';
591
592
import JSZip from ' jszip' ;
592
593
import axios from ' axios' ;
593
594
import { v4 as uuidv4 } from ' uuid' ;
595
+ import { saveAs } from ' file-saver' ;
594
596
595
597
import Message from ' vue-m-message' ;
596
598
import SlideEditorV from ' ./slide-editor.vue' ;
@@ -1334,6 +1336,20 @@ export default class MetadataEditorV extends Vue {
1334
1336
this .temporaryMetadataCopy = JSON .parse (JSON .stringify (this .metadata ));
1335
1337
}
1336
1338
1339
+ exportProduct(): void {
1340
+ this .generateConfig (false );
1341
+
1342
+ this .configFileStructure ?.zip .generateAsync ({ type: ' blob' }).then (
1343
+ (blob ) => {
1344
+ saveAs (blob , ` ${this .configFileStructure ?.uuid }.zip ` );
1345
+ Message .success (this .$t (' editor.export.success' ));
1346
+ },
1347
+ (err ) => {
1348
+ Message .error (this .$t (' editor.export.error' ));
1349
+ }
1350
+ );
1351
+ }
1352
+
1337
1353
/**
1338
1354
* Conducts various checks before saving.
1339
1355
*/
@@ -1345,9 +1361,9 @@ export default class MetadataEditorV extends Vue {
1345
1361
1346
1362
/**
1347
1363
* Called when `Save Changes` is pressed. Re-generates the Storylines configuration file
1348
- * with the new changes, then generates and submits the product file to the server.
1364
+ * with the new changes, and if `publish` is set to true, generates and submits the product file to the server.
1349
1365
*/
1350
- generateConfig(): ConfigFileStructure {
1366
+ generateConfig(publish = true ): ConfigFileStructure {
1351
1367
this .saving = true ;
1352
1368
1353
1369
// Update the configuration files, for both languages.
@@ -1370,97 +1386,107 @@ export default class MetadataEditorV extends Vue {
1370
1386
this .configFileStructure ?.zip .file (frFileName , frFormattedConfigFile );
1371
1387
1372
1388
// Upload the ZIP file.
1373
- this .configFileStructure ?.zip .generateAsync ({ type: ' blob' }).then ((content : Blob ) => {
1374
- const formData = new FormData ();
1375
- formData .append (' data' , content , ` ${this .uuid }.zip ` );
1376
- const userStore = useUserStore ();
1377
- const headers = { ' Content-Type' : ' multipart/form-data' , user: userStore .userProfile .userName || ' Guest' };
1378
- Message .warning (this .$t (' editor.editMetadata.message.wait' ));
1389
+ if (publish ) {
1390
+ this .configFileStructure ?.zip .generateAsync ({ type: ' blob' }).then ((content : Blob ) => {
1391
+ const formData = new FormData ();
1392
+ formData .append (' data' , content , ` ${this .uuid }.zip ` );
1393
+ const userStore = useUserStore ();
1394
+ const headers = {
1395
+ ' Content-Type' : ' multipart/form-data' ,
1396
+ user: userStore .userProfile .userName || ' Guest'
1397
+ };
1398
+ Message .warning (this .$t (' editor.editMetadata.message.wait' ));
1399
+
1400
+ axios
1401
+ .post (this .apiUrl + ' /upload' , formData , { headers })
1402
+ .then ((res : AxiosResponse ) => {
1403
+ const responseData = res .data ;
1404
+ responseData .files ; // binary representation of the file
1405
+ responseData .status ; // HTTP status
1406
+ const commitHash = responseData .commitHash ; // commit hash of the git commit
1407
+ this .unsavedChanges = false ;
1408
+ this .loadExisting = true ; // if editExisting was false, we can now set it to true
1409
+
1410
+ if (import .meta .env .VITE_APP_CURR_ENV ) {
1411
+ if (responseData .new ) {
1412
+ axios
1413
+ .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/user/register' , {
1414
+ uuid: this .uuid ,
1415
+ titleEn: this .configs [' en' ]?.title ?? ' ' ,
1416
+ titleFr: this .configs [' fr' ]?.title ?? ' '
1417
+ })
1418
+ .then ((response : any ) => {
1419
+ const userStore = useUserStore ();
1420
+ userStore .fetchUserProfile ();
1421
+ formData .append (' uuid' , this .uuid );
1422
+ formData .append (' titleEn' , this .configs [' en' ]?.title ?? ' ' );
1423
+ formData .append (' titleFr' , this .configs [' fr' ]?.title ?? ' ' );
1424
+ formData .append (' commitHash' , commitHash );
1425
+ formData .delete (' data' ); // Remove the data from the form so that we don't pass it into the .NET API
1426
+ axios
1427
+ .post (
1428
+ import .meta .env .VITE_APP_NET_API_URL + ' /api/version/commit' ,
1429
+ formData
1430
+ )
1431
+ .then ((response : any ) => {
1432
+ Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1433
+ })
1434
+ .catch ((error : any ) => console .log (error .response || error ))
1435
+ .finally (() => {
1436
+ // padding to prevent save button from being clicked rapidly
1437
+ setTimeout (() => {
1438
+ this .saving = false ;
1439
+ }, 500 );
1440
+ });
1441
+ })
1442
+ .catch ((error : any ) => console .log (error .response || error ));
1443
+ } else {
1444
+ formData .append (' uuid' , this .uuid );
1445
+ formData .append (' titleEn' , this .configs [' en' ]?.title ?? ' ' );
1446
+ formData .append (' titleFr' , this .configs [' fr' ]?.title ?? ' ' );
1447
+ formData .append (' commitHash' , commitHash );
1448
+ formData .delete (' data' ); // Remove the data from the form so that we don't pass it into the .NET API
1449
+ axios
1450
+ .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/version/commit' , formData )
1451
+ .then ((response : any ) => {
1452
+ Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1453
+ })
1454
+ .catch ((error : any ) => console .log (error .response || error ))
1455
+ .finally (() => {
1456
+ // padding to prevent save button from being clicked rapidly
1457
+ setTimeout (() => {
1458
+ this .saving = false ;
1459
+ }, 500 );
1460
+ });
1461
+ }
1379
1462
1380
- axios
1381
- .post (this .apiUrl + ' /upload' , formData , { headers })
1382
- .then ((res : AxiosResponse ) => {
1383
- const responseData = res .data ;
1384
- responseData .files ; // binary representation of the file
1385
- responseData .status ; // HTTP status
1386
- const commitHash = responseData .commitHash ; // commit hash of the git commit
1387
- this .unsavedChanges = false ;
1388
- this .loadExisting = true ; // if editExisting was false, we can now set it to true
1389
-
1390
- if (import .meta .env .VITE_APP_CURR_ENV ) {
1391
- if (responseData .new ) {
1392
- axios
1393
- .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/user/register' , {
1394
- uuid: this .uuid ,
1395
- titleEn: this .configs [' en' ]?.title ?? ' ' ,
1396
- titleFr: this .configs [' fr' ]?.title ?? ' '
1463
+ fetch (this .apiUrl + ` /retrieveMessages ` )
1464
+ .then ((res : any ) => {
1465
+ if (res .ok ) return res .json ();
1397
1466
})
1398
- .then ((response : any ) => {
1399
- const userStore = useUserStore ();
1400
- userStore .fetchUserProfile ();
1401
- formData .append (' uuid' , this .uuid );
1402
- formData .append (' titleEn' , this .configs [' en' ]?.title ?? ' ' );
1403
- formData .append (' titleFr' , this .configs [' fr' ]?.title ?? ' ' );
1404
- formData .append (' commitHash' , commitHash );
1405
- formData .delete (' data' ); // Remove the data from the form so that we don't pass it into the .NET API
1467
+ .then ((data ) => {
1406
1468
axios
1407
- .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/version/commit' , formData )
1408
- .then ((response : any ) => {
1409
- Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1469
+ .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/log/create' , {
1470
+ messages: data .messages
1410
1471
})
1411
- .catch ((error : any ) => console .log (error .response || error ))
1412
- .finally (() => {
1413
- // padding to prevent save button from being clicked rapidly
1414
- setTimeout (() => {
1415
- this .saving = false ;
1416
- }, 500 );
1417
- });
1472
+ .catch ((error : any ) => console .log (error .response || error ));
1418
1473
})
1419
1474
.catch ((error : any ) => console .log (error .response || error ));
1420
1475
} else {
1421
- formData .append (' uuid' , this .uuid );
1422
- formData .append (' titleEn' , this .configs [' en' ]?.title ?? ' ' );
1423
- formData .append (' titleFr' , this .configs [' fr' ]?.title ?? ' ' );
1424
- formData .append (' commitHash' , commitHash );
1425
- formData .delete (' data' ); // Remove the data from the form so that we don't pass it into the .NET API
1426
- axios
1427
- .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/version/commit' , formData )
1428
- .then ((response : any ) => {
1429
- Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1430
- })
1431
- .catch ((error : any ) => console .log (error .response || error ))
1432
- .finally (() => {
1433
- // padding to prevent save button from being clicked rapidly
1434
- setTimeout (() => {
1435
- this .saving = false ;
1436
- }, 500 );
1437
- });
1476
+ Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1477
+ // padding to prevent save button from being clicked rapidly
1478
+ setTimeout (() => {
1479
+ this .saving = false ;
1480
+ }, 500 );
1438
1481
}
1439
-
1440
- fetch (this .apiUrl + ` /retrieveMessages ` )
1441
- .then ((res : any ) => {
1442
- if (res .ok ) return res .json ();
1443
- })
1444
- .then ((data ) => {
1445
- axios
1446
- .post (import .meta .env .VITE_APP_NET_API_URL + ' /api/log/create' , {
1447
- messages: data .messages
1448
- })
1449
- .catch ((error : any ) => console .log (error .response || error ));
1450
- })
1451
- .catch ((error : any ) => console .log (error .response || error ));
1452
- } else {
1453
- Message .success (this .$t (' editor.editMetadata.message.successfulSave' ));
1454
- // padding to prevent save button from being clicked rapidly
1455
- setTimeout (() => {
1456
- this .saving = false ;
1457
- }, 500 );
1458
- }
1459
- })
1460
- .catch (() => {
1461
- Message .error (this .$t (' editor.editMetadata.message.error.failedSave' ));
1462
- });
1463
- });
1482
+ })
1483
+ .catch (() => {
1484
+ Message .error (this .$t (' editor.editMetadata.message.error.failedSave' ));
1485
+ });
1486
+ });
1487
+ } else {
1488
+ this .saving = false ;
1489
+ }
1464
1490
1465
1491
return this .configFileStructure as ConfigFileStructure ;
1466
1492
}
0 commit comments