private async void RemoveButton_Click(object sender, RoutedEventArgs e) { ContentDialog confirmation = new ContentDialog { Title = "Are you sure?", Content = "Once deleted, this page and its contents cannot be recovered", PrimaryButtonText = "Nevermind", SecondaryButtonText = "I'm sure" }; if (await confirmation.ShowAsync() == ContentDialogResult.Primary) { // nevermind // dismiss dialog and do nothing else confirmation.Hide(); } else { // i'm sure // actually remove the page WebPageManager.Pages.Remove(Page); await WebPageManager.Save(); // dismiss dialog confirmation.Hide(); // go back home with drill animation Frame.Navigate(typeof(Home), null, new DrillInNavigationTransitionInfo()); } }
private async Task SyncListItems() { if (!WebPageManager.Loaded) { await WebPageManager.Load(); } if (WebPageManager.Pages.Count != 0) { ListItems.Clear(); foreach (ManagedWebPage page in WebPageManager.Pages) { ListItems.Add(new WebPageListItem(page.Title, page.RelativeURL, page.GetLastUpdatedAsString())); } } else { ListItems = new ObservableCollection <WebPageListItem>(); } WebPagesListView.ItemsSource = ListItems; // build autosuggestbox itemssource AutoSuggestItems.Clear(); OriginalAutoSuggestItems.Clear(); foreach (ManagedWebPage page in WebPageManager.Pages) { AutoSuggestItems.Add(page.RelativeURL); OriginalAutoSuggestItems.Add(page.RelativeURL); } NewPageTextBox.ItemsSource = AutoSuggestItems; }
private async void DeployButton_Click(object sender, RoutedEventArgs e) { WebPageManager.SetSelected(Page); await WebPageManager.Save(); DeployDialog dialog = new DeployDialog(WebPageManager.GetSelectedPage()); await dialog.ShowAsync(); LoadDetails(); }
private async void SaveChangesButton_Click(object sender, RoutedEventArgs e) { Page.Updated(); Page.Title = TitleTextBox.Text; string t = ContentHTMLTextBox.Text; Page.ContentHTML = t; t = HeaderHTMLTextBox.Text; Page.AdditionalHeaderHTML = t; WebPageManager.SetSelected(Page); await WebPageManager.Save(); LoadDetails(); }
private void LoadDetails() { Page = WebPageManager.GetSelectedPage(); TitleTextBox.Text = Page.Title; TitleTextBlock.Text = "Edit \"" + Page.Title + "\" Details"; RelativeURLTextBlock.Text = Page.RelativeURL; // tool tip for when URL is too long to show all of it ToolTipService.SetToolTip(RelativeURLTextBlock, new ToolTip() { Content = Page.RelativeURL }); LastUpdatedTextBlock.Text = Page.GetLastUpdatedAsString(); LastSubmittedTextBlock.Text = Page.GetLastSubmittedAsString(); ContentHTMLTextBox.Text = Page.ContentHTML; HeaderHTMLTextBox.Text = Page.AdditionalHeaderHTML; }
private async Task Deploy() { DateTime start = DateTime.Now; double interval = 100.0 / DeployPages.Count; int i = 1; DeployProgressBar.Value = 0; bool test = DeveloperOptions.GetUseTestDirectory(); bool blank = DeveloperOptions.GetBlankDeploy(); if (DeveloperOptions.GetLocalDeploy()) { StorageFolder deployFolder = null; if (await FileManager.GetExists(ApplicationData.Current.LocalFolder, "deploy")) { deployFolder = (StorageFolder)(await ApplicationData.Current.LocalFolder.TryGetItemAsync("deploy")); await deployFolder.DeleteAsync(); } deployFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("deploy"); foreach (ManagedWebPage page in DeployPages) { StatusTextBlock.Text = $"{(DeployProgressBar.Value.ToString("0.00") + "%")} complete ({i} of {DeployPages.Count})"; Log($"\"{page.Title}\"... (Creating...)"); StorageFile indexHtml = await FileManager.CreateTemporaryFile(HTMLBuilder.GetFullPageHTML(page)); StorageFolder pageFolder = deployFolder, prev = deployFolder; if (page.RelativeURL.Length > 1) { // recursively create folders String[] dirs = page.RelativeURL.Split('/'); for (int ii = 0; ii < dirs.Length; ii++) { if (dirs[ii].Equals("")) { continue; } StorageFolder temp = prev; if (await prev.TryGetItemAsync(dirs[ii]) == null) { prev = await temp.CreateFolderAsync(dirs[ii]); } else { prev = (StorageFolder)await temp.TryGetItemAsync(dirs[ii]); } pageFolder = prev; } } // copy from temp to deploy if (pageFolder != null) { await indexHtml.CopyAsync(pageFolder); // not home page, and needs its own directory } else { await indexHtml.CopyAsync(deployFolder); // must be home page } await indexHtml.DeleteAsync(); LogTextBlock.Text = LogTextBlock.Text.Replace("(Creating...)", "(Done)"); DeployProgressBar.Value += interval; i++; page.Submitted(); } // save because submitted times were updated await WebPageManager.Save(); DeployProgressBar.Value = 100; StatusTextBlock.Text = $"Finished ({(DateTime.Now.Subtract(start).TotalSeconds.ToString("0.0"))} seconds)"; IsPrimaryButtonEnabled = true; Log("Opening in File Explorer..."); await Windows.System.Launcher.LaunchFolderAsync(deployFolder); return; } await FTPManager.Connect(); // await Task.Delay(5000); // await FTPManager.Disconnect(); Debug.Out("Connected!", "DEPLOY DIALOG"); foreach (ManagedWebPage page in DeployPages) { string path = page.RelativeURL; if (test) { path = $"/test{path}"; } string percent = DeployProgressBar.Value.ToString("0.00") + "%"; string msg = "\"" + page.RelativeURL + "\"... (Uploading...)"; StatusTextBlock.Text = percent + " complete (" + i + " of " + DeployPages.Count + ")"; Log(msg); if (!blank) { StorageFile file = await FileManager.CreateTemporaryFile(HTMLBuilder.GetFullPageHTML(page)); await FTPManager.UploadFile(file, path); await file.DeleteAsync(); LogTextBlock.Text = LogTextBlock.Text.Replace("(Uploading...)", "(Finished)"); } DeployProgressBar.Value += interval; i++; page.Submitted(); } await FTPManager.Disconnect(); // save because submitted times were updated await WebPageManager.Save(); string timeTaken = DateTime.Now.Subtract(start).TotalSeconds.ToString("0.0"); DeployProgressBar.Value = 100; StatusTextBlock.Text = "Finished (" + timeTaken + " seconds)"; IsPrimaryButtonEnabled = true; }
private void WebPagesListView_ItemClick(object sender, ItemClickEventArgs e) { WebPageManager.SelectedPageIndex = WebPageManager.Pages.IndexOf(WebPageManager.GetPage(((WebPageListItem)e.ClickedItem).URL)); Frame.Navigate(typeof(EditWebPage), null, new Windows.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo()); }
private async void AddNewPageButton_Click(object sender, RoutedEventArgs e) { string url = NewPageTextBox.Text; // validate input if (url.Length == 0) { // don't throw a validation error, because it is pretty obvious what the problem is return; } if (!url.StartsWith("/")) { await ThrowValidationError("Must start with \"/\" (relative to \"https://egartley.net\")"); return; } if (!url.EndsWith("/")) { await ThrowValidationError("Must end with \"/\""); return; } if (url.Contains(" ")) { await ThrowValidationError("Cannot contain spaces (consider using \"-\" or \"%20\" instead)"); return; } if (!Utils.IsValidURL(url)) { await ThrowValidationError("Invalid URL"); return; } if (OriginalAutoSuggestItems.Contains(url)) { await ThrowValidationError("That page already exists"); return; } // add new TextBlock (list item) to ListItems collection ListItems.Add(new WebPageListItem("Untitled Page", url, "Never")); // also add a new ManagedWebPage to WebPageManager.Pages WebPageManager.Pages.Add(new ManagedWebPage(url)); if (ListItems.Count > 1) { WebPageManager.Sort(); ListItems.Clear(); foreach (ManagedWebPage page in WebPageManager.Pages) { ListItems.Add(new WebPageListItem(page.Title, page.RelativeURL, page.GetLastUpdatedAsString())); } } // otherwise there is only one page, so there is no point in sorting // save new page await WebPageManager.Save(); // update UI NewPageTextBox.Text = ""; WebPagesListView.ItemsSource = ListItems; }