Commit c54534a9 authored by Francesco Carraro's avatar Francesco Carraro
Browse files

fixed save/delete procedure with permission

parent 3414c55e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            /* clear chart page (remove all spectra) and close usercontrols */
            await clearChartPageAsync();

            /* clear REF white (is not removed by removing the RAW one 'cause is not considered as a 'child' spectrum) */
            /* clear REF white (is not removed by removing the RAW one because is not considered as a 'child' spectrum) */
            WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.Ref);
        }
        #endregion
+4 −1
Original line number Diff line number Diff line
@@ -430,9 +430,12 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                        /* delete local file */
                        await deleteSpectrumLocallyAsync(retrievedSpectrumTypeToBeDeleted);

                        if (isDeleteOnCloudRequired)
                        /* delete file on cloud, ONLY IF asked by user AND permission is granted */
                        if (isDeleteOnCloudRequired && getPermissionsHelper().isSaveOnCloudFromAppAllowed())
                        {
                            /* delete file on cloud */
                            await deleteSpectrumOnCloudAsync(getFileId(retrievedSpectrumTypeToBeDeleted));
                        }

                        /* specific actions for spectra types */
                        switch (retrievedSpectrumTypeToBeDeleted)
+21 −17
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                initActionQuestionViewModel(question: "AlignmentAskDeletingContinuumRemoved".GetText(),
                                            optionalQuestion: "OptionalActionDeleteOnCloudQuestion".GetText(),
                                            isOptionalActionChecked: false,
                                            isOptionalActionVisible: true);
                                            isOptionalActionVisible: getPermissionsHelper().isSaveOnCloudFromAppAllowed());
            }
        }

@@ -97,6 +97,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            else
                showDialogMessage("SaveSpectrumLocalOutputFolderNotDefinedMessage".GetText(), DialogMessageType.Warning);

            /* if no permission to save/delete on cloud is granted, then return */
            if (getPermissionsHelper().isSaveOnCloudFromAppAllowed())
            {
                /* save aligned spectrum on cloud */
                GenericIdResponseModel saveCloudFileResult = await AlignmentViewModel.saveSpectrumOfTypeAlignedOnCloudAsync();
                if (saveCloudFileResult == null)
@@ -115,6 +118,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                /* save isSavedOnCloud and id of spectrum */
                WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Aligned).setIsSavedOnCloud(saveCloudFileResult.IsOk);
                WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.Aligned).setId(saveCloudFileResult.Id);
            }

            IsLoading = false;

+45 −28
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                /* init actionusercontrol viewmodel  */
                string question = "ContinuumRemovedAskDeletingContinuumRemoved".GetText();
                string optionalQuestion = "OptionalActionDeleteOnCloudQuestion".GetText();
                bool isOptionalActionVisible = true;
                bool isOptionalActionVisible = getPermissionsHelper().isSaveOnCloudFromAppAllowed();
                /* when continuum-removed is deleted because fit-segments are deleted... */
                if (isDeletingFitSegmentsInProgress)
                {
                    question = "ContinuumRemovedAskDeletingAlsoContinuumRemoved".GetText();
@@ -59,7 +60,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                initActionQuestionViewModel(question: "SegmentsFitAskDeletingSegmentFitModels".GetText(),
                                            optionalQuestion: string.Empty,
                                            isOptionalActionChecked: false,
                                            isOptionalActionVisible: false);
                                            isOptionalActionVisible: getPermissionsHelper().isSaveOnCloudFromAppAllowed());
            }
        }

@@ -244,7 +245,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        #endregion

        #region save
        private async Task saveSpectrumOfTypeContinuumRemovedAsync(RemoteOperationType remoteOperationType)
        private async Task saveSpectrumOfTypeContinuumRemovedAsync(SaveFileOperationType saveFileOperationType)
        {
            /* raise error message if no aligned spectrum existing */
            if (!WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.ContinuumRemoved))
@@ -258,15 +259,29 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            /* save aligned spectrum locally, in a local folder */
            if (await isOutputFolderDefinedAsync())
            {
                (bool isOk, string exMsg) saveLocalFileResult = await SegmentsFitViewModel.saveSpectrumOfTypeAsLocalFileAsync(SpectrumType.ContinuumRemoved);
                /* determine whether replace or create new version of local file */
                Windows.Storage.CreationCollisionOption creationCollisionOption = Windows.Storage.CreationCollisionOption.ReplaceExisting;
                if (saveFileOperationType == SaveFileOperationType.SaveAsCopy)
                    creationCollisionOption = Windows.Storage.CreationCollisionOption.GenerateUniqueName;

                (bool isOk, string exMsg) saveLocalFileResult = await SegmentsFitViewModel.saveSpectrumOfTypeAsLocalFileAsync(SpectrumType.ContinuumRemoved,
                                                                                                                              creationCollisionOption);
                if (!saveLocalFileResult.isOk)
                    showDialogMessage(saveLocalFileResult.exMsg, DialogMessageType.Warning);
            }
            else
                showDialogMessage("SaveSpectrumLocalOutputFolderNotDefinedMessage".GetText(), DialogMessageType.Warning);

            /* if no permission to save/delete on cloud is granted, then return */
            if (getPermissionsHelper().isSaveOnCloudFromAppAllowed())
            {
                /* determine whether replace or create new version on cloud */
                RemoteOperationType remoteOperationType = RemoteOperationType.SaveSpectrumOfTypeContinuumRemoved;
                if (saveFileOperationType == SaveFileOperationType.SaveAsCopy)
                    remoteOperationType = RemoteOperationType.SaveAsCopySpectrumOfTypeContinuumRemoved;

                /* save continuum-removed spectrum on cloud */
            SegmentsProcessingResponseModel saveCloudFileResult = await SegmentsFitViewModel.saveSpectrumOfTypeAlignedOnCloudAsync(remoteOperationType);
                SegmentsProcessingResponseModel saveCloudFileResult = await SegmentsFitViewModel.saveSpectrumOfTypeContinuumRemovedOnCloudAsync(remoteOperationType);
                if (saveCloudFileResult == null)
                {
                    IsLoading = false;
@@ -293,7 +308,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                {
                    SegmentsFitViewModel.setSegmentId(segment.Id, segment.XStart, segment.XEnd);
                }
            }

            /* used for show/hide save buttons (the one for upsert, the one for save-as-a-copy) */
            SegmentsFitViewModel.IsContinuumRemovedSaved = true;

            IsLoading = false;
+25 −24
Original line number Diff line number Diff line
@@ -2,8 +2,6 @@
using INAF.Apps.Uwp.SLabDataManager.Helpers;
using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart.ProcessingHelpers;
using INAF.Apps.Uwp.SLabDataManager.ViewModels.UserControlViewModels;
using INAF.Apps.Uwp.SLabDataManager.Views.UserControls;
using INAF.Libraries.NetStandard.Extensions;
using INAF.Libraries.NetStandard.ScienceModels.Extensions;
using INAF.Libraries.NetStandard.ScienceModels.Spectra;
using INAF.Libraries.NetStandard.SLabCommonModels.Models.WebApp.Responses;
@@ -41,7 +39,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                initActionQuestionViewModel(question: "SmoothingAskDeletingSmoothedSpectrumBySegments".GetText(),
                                            optionalQuestion: "OptionalActionDeleteOnCloudQuestion".GetText(),
                                            isOptionalActionChecked: false,
                                            isOptionalActionVisible: true);
                                            isOptionalActionVisible: getPermissionsHelper().isSaveOnCloudFromAppAllowed());
            }
        }

@@ -70,7 +68,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                initActionQuestionViewModel(question: "SmoothingAskDeletingSmoothedSpectrum".GetText(),
                                            optionalQuestion: "OptionalActionDeleteOnCloudQuestion".GetText(),
                                            isOptionalActionChecked: false,
                                            isOptionalActionVisible: true);
                                            isOptionalActionVisible: getPermissionsHelper().isSaveOnCloudFromAppAllowed());
            }
        }

@@ -309,6 +307,8 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            else
                showDialogMessage("SaveSpectrumLocalOutputFolderNotDefinedMessage".GetText(), DialogMessageType.Warning);

            if (getPermissionsHelper().isSaveOnCloudFromAppAllowed())
            {
                /* save smoothed spectrum on cloud */
                SegmentsProcessingResponseModel saveCloudFileResult = await SmoothingViewModel.saveSpectrumOfTypeSmoothedOnCloudAsync(destSpectrumType);
                if (saveCloudFileResult == null)
@@ -333,6 +333,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
                {
                    smoothingViewModel.setSegmentId(segment.Id, segment.XStart, segment.XEnd);
                }
            }

            IsLoading = false;

Loading