Esempio n. 1
0
        public delegate EditingView Factory();        //autofac uses this


        public EditingView(EditingModel model, PageListView pageListView, TemplatePagesView templatePagesView,
                           CutCommand cutCommand, CopyCommand copyCommand, PasteCommand pasteCommand, UndoCommand undoCommand, DuplicatePageCommand duplicatePageCommand,
                           DeletePageCommand deletePageCommand, NavigationIsolator isolator)
        {
            _model                = model;
            _pageListView         = pageListView;
            _templatePagesView    = templatePagesView;
            _cutCommand           = cutCommand;
            _copyCommand          = copyCommand;
            _pasteCommand         = pasteCommand;
            _undoCommand          = undoCommand;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand    = deletePageCommand;
            InitializeComponent();
            _browser1.Isolator   = isolator;
            _splitContainer1.Tag = _splitContainer1.SplitterDistance;            //save it
            //don't let it grow automatically
//            _splitContainer1.SplitterMoved+= ((object sender, SplitterEventArgs e) => _splitContainer1.SplitterDistance = (int)_splitContainer1.Tag);
            SetupThumnailLists();
            _model.SetView(this);
            _browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand);

            _browser1.GeckoReady += new EventHandler(OnGeckoReady);

            _menusToolStrip.Renderer = new FixedToolStripRenderer();

            //we're giving it to the parent control through the TopBarControls property
            Controls.Remove(_topBarPanel);
        }
Esempio n. 2
0
        //autofac uses this
        public EditingView(EditingModel model, PageListView pageListView,
			CutCommand cutCommand, CopyCommand copyCommand, PasteCommand pasteCommand, UndoCommand undoCommand,
			DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand, NavigationIsolator isolator, ControlKeyEvent controlKeyEvent)
        {
            _model = model;
            _pageListView = pageListView;
            _cutCommand = cutCommand;
            _copyCommand = copyCommand;
            _pasteCommand = pasteCommand;
            _undoCommand = undoCommand;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand = deletePageCommand;
            InitializeComponent();
            _browser1.Isolator = isolator;
            _splitContainer1.Tag = _splitContainer1.SplitterDistance; //save it
            //don't let it grow automatically
            //            _splitContainer1.SplitterMoved+= ((object sender, SplitterEventArgs e) => _splitContainer1.SplitterDistance = (int)_splitContainer1.Tag);
            SetupThumnailLists();
            _model.SetView(this);
            _browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand);

            _browser1.GeckoReady += new EventHandler(OnGeckoReady);

            _browser1.ControlKeyEvent = controlKeyEvent;

            if(SIL.PlatformUtilities.Platform.IsMono)
            {
                RepositionButtonsForMono();
                BackgroundColorsForLinux();
            }

            controlKeyEvent.Subscribe(HandleControlKeyEvent);

            // Adding this renderer prevents a white line from showing up under the components.
            _menusToolStrip.Renderer = new FixedToolStripRenderer();

            //we're giving it to the parent control through the TopBarControls property
            Controls.Remove(_topBarPanel);
            SetupBrowserContextMenu();
            #if __MonoCS__
            // The inactive button images look garishly pink on Linux/Mono, but look okay on Windows.
            // Merely introducing an "identity color matrix" to the image attributes appears to fix
            // this problem.  (The active form looks okay with or without this fix.)
            // See http://issues.bloomlibrary.org/youtrack/issue/BL-3714.
            float[][] colorMatrixElements = {
                new float[] {1,  0,  0,  0,  0},		// red scaling factor of 1
                new float[] {0,  1,  0,  0,  0},		// green scaling factor of 1
                new float[] {0,  0,  1,  0,  0},		// blue scaling factor of 1
                new float[] {0,  0,  0,  1,  0},		// alpha scaling factor of 1
                new float[] {0,  0,  0,  0,  1}};		// three translations of 0.0
            var colorMatrix = new ColorMatrix(colorMatrixElements);
            _duplicatePageButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            _deletePageButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            _undoButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            _cutButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            _pasteButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            _copyButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            #endif
        }
        public delegate EditingModel Factory();        //autofac uses this

        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
                            LanguageSettings languageSettings,
                            TemplateInsertionCommand templateInsertionCommand,
                            PageListChangedEvent pageListChangedEvent,
                            RelocatePageEvent relocatePageEvent,
                            BookRefreshEvent bookRefreshEvent,
                            DuplicatePageCommand duplicatePageCommand,
                            DeletePageCommand deletePageCommand,
                            SelectedTabChangedEvent selectedTabChangedEvent,
                            SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
                            LibraryClosing libraryClosingEvent,
                            LocalizationChangedEvent localizationChangedEvent,
                            CollectionSettings collectionSettings,
                            SendReceiver sendReceiver,
                            EnhancedImageServer server)
        {
            _bookSelection        = bookSelection;
            _pageSelection        = pageSelection;
            _languageSettings     = languageSettings;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand    = deletePageCommand;
            _collectionSettings   = collectionSettings;
            _sendReceiver         = sendReceiver;
            _server = server;

            bookSelection.SelectionChanged      += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged      += new EventHandler(OnPageSelectionChanged);
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer    = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o => SaveNow());
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                    _view.UpdateTemplateList();
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List <ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
            _server.CurrentBook = CurrentBook;
        }
 public Task DuplicateAsync(DuplicatePageCommand command)
 {
     return(ExtendableContentRepository.ExecuteCommandAsync(command));
 }
Esempio n. 5
0
        public async Task <int> DuplicateAsync(DuplicatePageCommand command)
        {
            await ExtendableContentRepository.ExecuteCommandAsync(command);

            return(command.OutputPageId);
        }
Esempio n. 6
0
 public async Task <IActionResult> Post([FromBody] DuplicatePageCommand command)
 {
     return(await _apiResponseHelper.RunCommandAsync(this, command));
 }
        public async Task CopiesBasicData()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CopiesBasicData);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var newDirectoryId = await app.TestData.PageDirectories().AddAsync(uniqueData + " Copy");

            var originalPageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c =>
            {
                c.MetaDescription      = uniqueData + " Meta";
                c.OpenGraphDescription = uniqueData + "OG Desc";
                c.OpenGraphImageId     = app.SeededEntities.TestImageId;
                c.OpenGraphTitle       = uniqueData + "OG Title";
                c.Publish = true;
            });

            var command = new DuplicatePageCommand()
            {
                PageToDuplicateId = originalPageId,
                PageDirectoryId   = newDirectoryId,
                Title             = uniqueData + " Page Copy",
                UrlPath           = "page-copy"
            };

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var newPageId         = await contentRepository
                                    .Pages()
                                    .DuplicateAsync(command);

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();

            var originalPage = await GetPageFromDb(originalPageId);

            var originalPageVersion = originalPage?.PageVersions.FirstOrDefault();
            var newPage             = await GetPageFromDb(newPageId);

            var newPageVersion = newPage?.PageVersions.FirstOrDefault();

            using (new AssertionScope())
            {
                originalPage.Should().NotBeNull();

                newPage.Should().NotBeNull();
                newPage.LocaleId.Should().Be(command.LocaleId);
                newPage.PageDirectoryId.Should().Be(command.PageDirectoryId);
                newPage.PageTypeId.Should().Be(originalPage.PageTypeId);
                newPage.PageVersions.Should().HaveCount(1);
                newPage.PublishDate.Should().BeNull();
                newPage.LastPublishDate.Should().BeNull();
                newPage.PublishStatusCode.Should().Be(PublishStatusCode.Unpublished);
                newPage.UrlPath.Should().Be(command.UrlPath);

                newPageVersion.Should().NotBeNull();
                newPageVersion.CreateDate.Should().BeAfter(originalPageVersion.CreateDate);
                newPageVersion.DisplayVersion.Should().Be(1);
                newPageVersion.ExcludeFromSitemap.Should().Be(originalPageVersion.ExcludeFromSitemap);
                newPageVersion.MetaDescription.Should().Be(originalPageVersion.MetaDescription);
                newPageVersion.OpenGraphDescription.Should().Be(originalPageVersion.OpenGraphDescription);
                newPageVersion.OpenGraphImageId.Should().Be(originalPageVersion.OpenGraphImageId);
                newPageVersion.OpenGraphTitle.Should().Be(originalPageVersion.OpenGraphTitle);
                newPageVersion.PageTemplateId.Should().Be(originalPageVersion.PageTemplateId);
                newPageVersion.PageVersionBlocks.Should().BeEmpty();
                newPageVersion.Title.Should().Be(command.Title);
                newPageVersion.WorkFlowStatusId.Should().Be((int)WorkFlowStatus.Draft);
            }
        }
        public async Task CopiesRegions()
        {
            var uniqueData = UNIQUE_PREFIX + nameof(CopiesRegions);

            using var app = _appFactory.Create();
            var directoryId = await app.TestData.PageDirectories().AddAsync(uniqueData);

            var originalPageId = await app.TestData.Pages().AddAsync(uniqueData, directoryId, c => c.Publish = true);

            var pageVersionId = await app.TestData.Pages().AddDraftAsync(originalPageId);

            var textBlockId = await app.TestData.Pages().AddPlainTextBlockToTestTemplateAsync(pageVersionId, uniqueData);

            var imageBlockId = await app.TestData.Pages().AddImageTextBlockToTestTemplateAsync(pageVersionId);

            var command = new DuplicatePageCommand()
            {
                PageToDuplicateId = originalPageId,
                PageDirectoryId   = directoryId,
                Title             = uniqueData + " Page Copy",
                UrlPath           = "page-copy"
            };

            var contentRepository = app.Services.GetContentRepositoryWithElevatedPermissions();
            var newPageId         = await contentRepository
                                    .Pages()
                                    .DuplicateAsync(command);

            // Prepare assertion data

            var originalPage = await GetPageFromDb(originalPageId);

            var originalPageVersion = originalPage?
                                      .PageVersions
                                      .Where(v => v.WorkFlowStatusId == (int)WorkFlowStatus.Draft)
                                      .FirstOrDefault();
            var newPage = await GetPageFromDb(newPageId);

            var newPageVersion = newPage?.PageVersions.FirstOrDefault();

            var originalVersionTextBlock = originalPageVersion?
                                           .PageVersionBlocks
                                           .SingleOrDefault(v => v.PageVersionBlockId == textBlockId);
            var originalVersionImageBlock = originalPageVersion?
                                            .PageVersionBlocks
                                            .SingleOrDefault(v => v.PageVersionBlockId == imageBlockId);

            var newVersionTextBlock = newPageVersion
                                      .PageVersionBlocks
                                      .FirstOrDefault(v => v.PageBlockTypeId == originalVersionTextBlock?.PageBlockTypeId);
            var newVersionImageBlock = newPageVersion
                                       .PageVersionBlocks
                                       .FirstOrDefault(v => v.PageBlockTypeId == originalVersionImageBlock?.PageBlockTypeId);

            var newVersionImageBlockId = newVersionImageBlock?.PageVersionBlockId;

            var dbContext = app.Services.GetRequiredService <CofoundryDbContext>();
            var unstructuredDependencies = await dbContext
                                           .UnstructuredDataDependencies
                                           .AsNoTracking()
                                           .Where(v => v.RootEntityDefinitionCode == PageVersionBlockEntityDefinition.DefinitionCode && v.RootEntityId == newVersionImageBlockId)
                                           .ToListAsync();

            var copiedImageDependency = unstructuredDependencies.SingleOrDefault();

            // Assert

            using (new AssertionScope())
            {
                originalPageVersion.Should().NotBeNull();
                newPageVersion.Should().NotBeNull();
                newPageVersion.WorkFlowStatusId.Should().Be((int)WorkFlowStatus.Draft);
                newPageVersion.PageVersionBlocks.Should().HaveCount(originalPageVersion.PageVersionBlocks.Count);

                AssertBlockMatches(originalVersionTextBlock, newVersionTextBlock);
                AssertBlockMatches(originalVersionImageBlock, newVersionImageBlock);
                unstructuredDependencies.Should().HaveCount(1);
                copiedImageDependency.Should().NotBeNull();
                copiedImageDependency.RelatedEntityId.Should().Be(app.SeededEntities.TestImageId);
                copiedImageDependency.RelatedEntityDefinitionCode.Should().Be(ImageAssetEntityDefinition.DefinitionCode);
            }
Esempio n. 9
0
 public async Task <JsonResult> PostDuplicate([FromBody] DuplicatePageCommand command)
 {
     return(await _apiResponseHelper.RunCommandAsync(command));
 }
Esempio n. 10
0
        //autofac uses this
        public EditingModel(BookSelection bookSelection, PageSelection pageSelection,
			TemplateInsertionCommand templateInsertionCommand,
			PageListChangedEvent pageListChangedEvent,
			RelocatePageEvent relocatePageEvent,
			BookRefreshEvent bookRefreshEvent,
			PageRefreshEvent pageRefreshEvent,
			DuplicatePageCommand duplicatePageCommand,
			DeletePageCommand deletePageCommand,
			SelectedTabChangedEvent selectedTabChangedEvent,
			SelectedTabAboutToChangeEvent selectedTabAboutToChangeEvent,
			LibraryClosing libraryClosingEvent,
			LocalizationChangedEvent localizationChangedEvent,
			CollectionSettings collectionSettings,
			//SendReceiver sendReceiver,
			EnhancedImageServer server,
			BloomWebSocketServer webSocketServer)
        {
            _bookSelection = bookSelection;
            _pageSelection = pageSelection;
            _duplicatePageCommand = duplicatePageCommand;
            _deletePageCommand = deletePageCommand;
            _collectionSettings = collectionSettings;
            //_sendReceiver = sendReceiver;
            _server = server;
            _webSocketServer = webSocketServer;
            _templatePagesDict = null;

            bookSelection.SelectionChanged += new EventHandler(OnBookSelectionChanged);
            pageSelection.SelectionChanged += new EventHandler(OnPageSelectionChanged);
            pageSelection.SelectionChanging += OnPageSelectionChanging;
            templateInsertionCommand.InsertPage += new EventHandler(OnInsertTemplatePage);

            bookRefreshEvent.Subscribe((book) => OnBookSelectionChanged(null, null));
            pageRefreshEvent.Subscribe((PageRefreshEvent.SaveBehavior behavior) =>
            {
                switch (behavior)
                {
                    case PageRefreshEvent.SaveBehavior.SaveBeforeRefresh:
                        RethinkPageAndReloadIt(null);
                        break;

                    case PageRefreshEvent.SaveBehavior.JustRedisplay:
                        RefreshDisplayOfCurrentPage();
                        break;
                }
            });

            selectedTabChangedEvent.Subscribe(OnTabChanged);
            selectedTabAboutToChangeEvent.Subscribe(OnTabAboutToChange);
            duplicatePageCommand.Implementer = OnDuplicatePage;
            deletePageCommand.Implementer = OnDeletePage;
            pageListChangedEvent.Subscribe(x => _view.UpdatePageList(false));
            relocatePageEvent.Subscribe(OnRelocatePage);
            libraryClosingEvent.Subscribe(o =>
            {
                if (Visible)
                    SaveNow();
            });
            localizationChangedEvent.Subscribe(o =>
            {
                //this is visible was added for https://jira.sil.org/browse/BL-267, where the edit tab has never been
                //shown so the view has never been full constructed, so we're not in a good state to do a refresh
                if (Visible)
                {
                    SaveNow();
                    _view.UpdateButtonLocalizations();
                    RefreshDisplayOfCurrentPage();
                    //_view.UpdateDisplay();
                    _view.UpdatePageList(false);
                }
                else if (_view != null)
                {
                    // otherwise changing UI language in Publish tab (for instance) won't update these localizations
                    _view.UpdateButtonLocalizations();
                }
            });
            _contentLanguages = new List<ContentLanguage>();
            _server.CurrentCollectionSettings = _collectionSettings;
        }