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

fixed deleting of continuum-removed; fixed issue in removing legend item when spectrum is removed

parent b1fcda28
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
using INAF.Apps.Uwp.SLabDataManager.Charts.Containers;
using INAF.Apps.Uwp.SLabDataManager.Extensions;
using INAF.Apps.Uwp.SLabDataManager.Helpers.UI.Chart;
using INAF.Apps.Uwp.SLabDataManager.Models.Spectrum;
using System.Collections.Generic;
@@ -130,9 +131,9 @@ namespace INAF.Apps.Uwp.SLabDataManager.Helpers.UI
        public static async Task RemoveChartLegendItemAsync(RadLegendControl chartLegend,
                                                            SpectrumType spectrumType)
        {
            if (chartLegend.LegendItems.Any(x => x.Title.Contains(spectrumType.ToString(), System.StringComparison.InvariantCultureIgnoreCase)))
            if (chartLegend.LegendItems.Any(x => x.Title.Contains(spectrumType.GetDescription(), System.StringComparison.InvariantCultureIgnoreCase)))
            {
                var itemToBeRemoved = chartLegend.LegendItems.FirstOrDefault(x => x.Title.Contains(spectrumType.ToString()));
                var itemToBeRemoved = chartLegend.LegendItems.FirstOrDefault(x => x.Title.Contains(spectrumType.GetDescription()));
                chartLegend.LegendItems.Remove(itemToBeRemoved);
            }

+22 −4
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@
    <value>Selected spectrum file successfully parsed</value>
  </data>
  <data name="SpectrumFileReadingErrorMessage" xml:space="preserve">
    <value>An error occurred while trying ro read selected file, please check its content</value>
    <value>An error occurred while trying to read selected file, please check its content</value>
  </data>
  <data name="RawSpectrumSummaryLabel" xml:space="preserve">
    <value>RAW Spectrum summary</value>
@@ -534,10 +534,10 @@
  <data name="SegmentsFitButtonExecuteContinuumRemovalLabel.Text" xml:space="preserve">
    <value>Remove continuum</value>
  </data>
  <data name="SegmentsFitButtonRemoveContinuumLabel.Text" xml:space="preserve">
    <value>Remove continuum</value>
  <data name="SegmentsFitButtonDeleteContinuumRemovedSpectrumLabel.Text" xml:space="preserve">
    <value>Delete continuum-removed spectrum</value>
  </data>
  <data name="SegmentsFitButtonSaveContinuumLabel.Text" xml:space="preserve">
  <data name="SegmentsFitButtonSaveContinuumRemovedSpectrumLabel.Text" xml:space="preserve">
    <value>Save continuum</value>
  </data>
  <data name="SegmentsFitPivotItemFit.Header" xml:space="preserve">
@@ -573,4 +573,22 @@
  <data name="SpectrumButtonSaveSampleData.Text" xml:space="preserve">
    <value>Save sample data</value>
  </data>
  <data name="ContinuumRemovedSpectrumDeletingErrorMessage" xml:space="preserve">
    <value>An error occurred while trying to delete continuum-removed spectrum</value>
  </data>
  <data name="ContinuumRemovedSpectrumDeletingSuccessMessage" xml:space="preserve">
    <value>Continuum-removed spectrum has been successfully deleted</value>
  </data>
  <data name="ContinuumRemovedSpectrumDeletingTitle" xml:space="preserve">
    <value>Continuum-removed deletion</value>
  </data>
  <data name="AlignedSpectrumTitle" xml:space="preserve">
    <value>Spectrum alignment</value>
  </data>
  <data name="SampleDataSavingTitle" xml:space="preserve">
    <value>Sample data saving</value>
  </data>
  <data name="SampleDataSuccessfullySavedMessage" xml:space="preserve">
    <value>Sample data successfully saved!</value>
  </data>
</root>
 No newline at end of file
+10 −3
Original line number Diff line number Diff line
@@ -77,7 +77,14 @@
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ColorAnimation Duration="0" To="{ThemeResource TelerikDisabledColor}" Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                        Storyboard.TargetName="EllipseInner"/>
                                        <ColorAnimation Duration="0" To="{ThemeResource TelerikDisabledColor}" Storyboard.TargetProperty="(Ellipse.Fill).(SolidColorBrush.Color)"
                                                        Storyboard.TargetName="EllipseOuter"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="MouseOver"/>
                                <VisualState x:Name="Pressed">
@@ -96,12 +103,12 @@
                                <VisualState x:Name="Unfocused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Ellipse Margin="4" Fill="{ThemeResource SystemAccentColor}" RenderTransformOrigin="0.5,0.5">
                        <Ellipse x:Name="EllipseInner" Margin="4" Fill="{ThemeResource SystemAccentColor}" RenderTransformOrigin="0.5,0.5">
                            <Ellipse.RenderTransform>
                                <ScaleTransform ScaleY="1" x:Name="Outer"/>
                            </Ellipse.RenderTransform>
                        </Ellipse>
                        <Ellipse Margin="20" Fill="{ThemeResource SystemAccentColor}" RenderTransformOrigin="0.5,0.5">
                        <Ellipse x:Name="EllipseOuter" Margin="20" Fill="{ThemeResource SystemAccentColor}" RenderTransformOrigin="0.5,0.5">
                            <Ellipse.RenderTransform>
                                <ScaleTransform ScaleY="-1" x:Name="Inner"/>
                            </Ellipse.RenderTransform>
+0 −6
Original line number Diff line number Diff line
@@ -213,12 +213,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            }
        }

        private void raiseIsInfoBarOpen()
        {
            IsInfoBarOpen = true;
            isInfoBarOpen = false;
        }

        #region success/error messages
        protected void showSuccessMessage(string successText)
        {
+64 −37
Original line number Diff line number Diff line
@@ -360,7 +360,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            if (WorkingItems.SpectraContainer.SpectrumAlignmentConfig.isPinnedPending)
            {
                WorkingItems.SpectraContainer.SpectrumAlignmentConfig.IsPinRequested = true;
                var p = page.FindName("alignmentConfigUserControl");
                WorkingItems.SpectraContainer.SpectrumAlignmentConfig.IsPinned = true;
            }

@@ -512,7 +511,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels

            IsLoading = false;

            showSuccessMessage("AlignedSpectrumSavedSuccessfullyMessage".GetText());
            showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational,
                            "AlignedSpectrumTitle".GetText(),
                            "AlignedSpectrumSavedSuccessfullyMessage".GetText(),
                            autoHide: true);
            //showSuccessMessage("AlignedSpectrumSavedSuccessfullyMessage".GetText());
        }

        private async Task<(bool isOk, string exMsg)> saveSpectrumOfTypeAlignedAsLocalFileAsync()
@@ -651,6 +654,45 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        #endregion

        #region continuum
        private void askDeleteContinuumSpectrum()
        {
            if (WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.ContinuumRemoved))
            {
                if (WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.ContinuumRemoved).IsSavedOnCloud)
                    IsDeleteQuestionVisible = true;
            }
        }

        private async Task deleteContinuumRemovedSpectrumAsync()
        {
            var remoteOperationsManager = serviceProvider.GetRequiredService<RemoteOperationsManager>();

            var spectrum = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.ContinuumRemoved);

            if (await remoteOperationsManager.deleteSpectrumAsync(new DeleteSpectrumRequestModel() { Id = spectrum.Id }))
            {
                /* hide dialog question */
                IsDeleteQuestionVisible = false;

                /* remove spectrum from chart */
                WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.ContinuumRemoved);

                /* show success message */
                showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational,
                            "ContinuumRemovedSpectrumDeletingTitle".GetText(),
                            "ContinuumRemovedSpectrumDeletingSuccessMessage".GetText(),
                            autoHide: true);
            }
            else
            {
                /* hide dialog question */
                IsDeleteQuestionVisible = false;

                /* show error message */
                showDialogMessage("ContinuumRemovedSpectrumDeletingErrorMessage".GetText());
            }
        }

        private void executeContinuumRemovalProcedure()
        {
            IsLoading = true;
@@ -695,7 +737,7 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.Continuum);

            /* remove the continuum-removed spectrum, if existing */
            deleteContinuumSpectrumAsync();
            askDeleteContinuumSpectrum();
        }

        private bool isContinuumSpectrumCompleted()
@@ -803,35 +845,13 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels

            IsLoading = false;

            showSuccessMessage("ContinuumSpectrumSavedSuccessfullyMessage".GetText());
            showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational,
                        "ContinuumRemovalTitle".GetText(),
                        "ContinuumSpectrumSavedSuccessfullyMessage".GetText(),
                        autoHide: true);
        }

        private async Task deleteContinuumSpectrumAsync()
        {
            if (WorkingItems.SpectraContainer.isAnySpectrumOfType(SpectrumType.ContinuumRemoved))
            {
                var spectrum = WorkingItems.SpectraContainer.tryGetSpectrumOfType(SpectrumType.ContinuumRemoved);

                if (spectrum.IsSavedOnCloud)
                {

                    IsDeleteQuestionVisible = true;

                    var remoteOperationsManager = serviceProvider.GetRequiredService<RemoteOperationsManager>();
                    if (await remoteOperationsManager.deleteSpectrumAsync(new DeleteSpectrumRequestModel() { Id = spectrum.Id }))
                    {

                    }
                    else
                    {
        
                    }
                }
            }

            /* remove spectrum from chart */
            WorkingItems.SpectraContainer.tryRemoveSpectrumOfTypeAsync(SpectrumType.ContinuumRemoved);
        }

        private void setFocusEnabled(bool isOn)
        {
@@ -920,7 +940,11 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
            if (responseobj.IsOk)
            {
                logger.Write<MainViewModel>("SaveSpectrumOfTypeSuccessMessage".GetText().Replace("r_v", spectrumFilename), Serilog.Events.LogEventLevel.Information);
                showSuccessMessage("SaveSpectrumOfTypeSuccessMessage".GetText().Replace("r_v", spectrumFilename));
                showInfoBar(Microsoft.UI.Xaml.Controls.InfoBarSeverity.Informational,
                            "SampleDataSavingTitle".GetText(),
                            "SampleDataSuccessfullySavedMessage".GetText(),
                            autoHide: true);
                //showSuccessMessage("SaveSpectrumOfTypeSuccessMessage".GetText().Replace("r_v", spectrumFilename));
            }
            else
            {
@@ -933,9 +957,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        #endregion

        #region commands
        private RelayCommand commandCancelDelete;
        public RelayCommand CommandCancelDelete => commandCancelDelete ?? (commandCancelDelete = new RelayCommand(() => IsDeleteQuestionVisible = false));

        #region alignment
        private RelayCommand commandAlignSpectrum;
        public RelayCommand CommandAlignSpectrum => commandAlignSpectrum ?? (commandAlignSpectrum = new RelayCommand(() => executeSpectrumAlignmentAsync()));
@@ -948,9 +969,18 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        #endregion

        #region continuum
        private RelayCommand commandAskDeleteContinuumRemovedSpectrum;
        public RelayCommand CommandAskDeleteContinuumRemovedSpectrum => commandAskDeleteContinuumRemovedSpectrum ?? (commandAskDeleteContinuumRemovedSpectrum = new RelayCommand(() => askDeleteContinuumSpectrum()));

        private RelayCommand commandCancelDeleteContinuumRemovedSpectrum;
        public RelayCommand CommandCancelDeleteContinuumRemovedSpectrum => commandCancelDeleteContinuumRemovedSpectrum ?? (commandCancelDeleteContinuumRemovedSpectrum = new RelayCommand(() => IsDeleteQuestionVisible = false));

        private RelayCommand commandClearFitSegments;
        public RelayCommand CommandClearFitSegments => commandClearFitSegments ?? (commandClearFitSegments = new RelayCommand(() => clearSegmentsFitAndContinuumSpectra()));

        private RelayCommand commandDeleteContinuumRemovedSpectrum;
        public RelayCommand CommandDeleteContinuumRemovedSpectrum => commandDeleteContinuumRemovedSpectrum ?? (commandDeleteContinuumRemovedSpectrum = new RelayCommand(() => deleteContinuumRemovedSpectrumAsync()));

        //private RelayCommand commandFitContinuum;
        //public RelayCommand CommandFitContinuum => commandFitContinuum ?? (commandFitContinuum = new RelayCommand(() => fitContinuumAsync()));

@@ -960,9 +990,6 @@ namespace INAF.Apps.Uwp.SLabDataManager.ViewModels
        private RelayCommand commandExecuteContinuumRemoval;
        public RelayCommand CommandExecuteContinuumRemoval => commandExecuteContinuumRemoval ?? (commandExecuteContinuumRemoval = new RelayCommand(() => executeContinuumRemovalProcedure()));

        private RelayCommand commandDeleteContinuumSpectrum;
        public RelayCommand CommandDeleteContinuumSpectrum => commandDeleteContinuumSpectrum ?? (commandDeleteContinuumSpectrum = new RelayCommand(() => deleteContinuumSpectrumAsync()));

        private RelayCommand commandSaveContinuumSpectrum;
        public RelayCommand CommandSaveContinuumSpectrum => commandSaveContinuumSpectrum ?? (commandSaveContinuumSpectrum = new RelayCommand(() => saveSpectrumOfTypeContinuumRemovedAsync()));

Loading