Beispiel #1
0
        public void CreateDocument(MarkdownCategoryViewModel parent = null)
        {
            NameItemDialog dialog       = new NameItemDialog(DialogOwner, "New Note");
            bool?          dialogResult = dialog.ShowDialog();

            if (dialogResult.HasValue && dialogResult.Value)
            {
                MarkdownDocument doc = new MarkdownDocument(UniverseVm.Model.Connection);
                doc.Name         = dialog.UserInput;
                doc.UniverseId   = UniverseVm.Model.id;
                doc.MarkdownText = string.Format("# {0}\r\nThis is a new note document.", doc.Name);
                doc.PlainText    = Markdig.Markdown.ToPlainText(doc.MarkdownText);
                doc.Create();

                MarkdownDocumentViewModel docVm = new MarkdownDocumentViewModel(doc, UniverseVm);

                if (parent != null)
                {
                    MarkdownCategoryDocument link = new MarkdownCategoryDocument(UniverseVm.Model.Connection);
                    link.MarkdownDocumentId = doc.id;
                    link.MarkdownCategoryId = parent.Model.id;
                    link.Create();

                    docVm.Parent = parent;
                    parent.Children.Add(docVm);
                }
                else
                {
                    Items.Add(docVm);
                }
            }
        }
Beispiel #2
0
        public void CreateTicket()
        {
            Ticket ticket = new Ticket(UniverseVm.Model.Connection);

            ticket.UniverseId = UniverseVm.Model.id;
            ticket.Name       = "New Ticket";
            ticket.Priority   = 2;
            ticket.Status     = "Not Started";
            ticket.DueDate    = ""; // Not fully implemented.
            ticket.Create();

            // Create MarkdownDocument for ticket.
            MarkdownDocument doc = MarkdownDocumentViewModel.CreateDocForItem(ticket, ticket.UniverseId, true, string.Format("Ticket {0}", ticket.id));

            doc.MarkdownText = "New Ticket.";
            doc.PlainText    = Markdig.Markdown.ToPlainText(doc.MarkdownText);
            doc.Save();

            // Add to list.
            TicketViewModel vm = new TicketViewModel(ticket, this);

            Tickets.Add(vm);

            // Show edit dialog.
            vm.Edit();
        }
        public void Delete()
        {
            ConfirmDeleteDialog dialog = new ConfirmDeleteDialog(DialogOwner, "Its subitems will not be removed.");
            bool?result = dialog.ShowDialog();

            if (result.HasValue && result.Value)
            {
                Model.Delete();
                if (Parent != null)
                {
                    Parent.Children.Remove(this);
                    foreach (var item in Children)
                    {
                        if (item is MarkdownCategoryViewModel)
                        {
                            MarkdownCategoryViewModel child = (MarkdownCategoryViewModel)item;
                            child.Parent         = Parent;
                            child.Model.ParentId = (Parent as MarkdownCategoryViewModel).Model.id;
                            Parent.Children.Add(child);
                            child.Model.Save();
                        }
                        else
                        {
                            MarkdownDocumentViewModel child = (MarkdownDocumentViewModel)item;
                            child.Parent = Parent;

                            MarkdownCategoryDocument link = new MarkdownCategoryDocument(Model.Connection);
                            link.MarkdownCategoryId = (Parent as MarkdownCategoryViewModel).Model.id;
                            link.MarkdownDocumentId = child.Model.id;
                            link.Create();
                            Parent.Children.Add(child);
                        }
                    }
                }
                else
                {
                    if (UniverseVm.MarkdownTree.Items.Contains(this))
                    {
                        UniverseVm.MarkdownTree.Items.Remove(this);
                    }
                    foreach (var item in Children)
                    {
                        if (item is MarkdownCategoryViewModel)
                        {
                            MarkdownCategoryViewModel child = (MarkdownCategoryViewModel)item;
                            child.Parent         = null;
                            child.Model.ParentId = null;
                            child.Model.Save();
                            UniverseVm.MarkdownTree.Items.Add(child);
                        }
                        else
                        {
                            MarkdownDocumentViewModel child = (MarkdownDocumentViewModel)item;
                            UniverseVm.MarkdownTree.Items.Add(child);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public void RemoveFromTree(MarkdownDocumentViewModel doc)
 {
     if (Items.Contains(doc))
     {
         Items.Remove(doc);
     }
     foreach (var c in Categories)
     {
         if (c.Children.Contains(doc))
         {
             c.Children.Remove(doc);
         }
     }
 }
Beispiel #5
0
        public void UpdateDocumentCategories(MarkdownDocumentViewModel doc, IEnumerable <MarkdownCategoryViewModel> newCategories)
        {
            // First, load all document/category links from the database.
            var currentCategories = MarkdownCategoryDocument.GetCategoriesForDocument(doc.Model.Connection, doc.Model.id);

            // Delete any that were removed.
            foreach (var cat in currentCategories)
            {
                MarkdownCategoryViewModel vm = Categories.SingleOrDefault(i => i.Model.id == cat.MarkdownCategoryId);
                if (vm != null)
                {
                    cat.Delete();
                    vm.Children.Remove(doc);
                }
            }

            // Add new ones.
            foreach (var cat in newCategories)
            {
                MarkdownCategoryDocument dbLink = currentCategories.SingleOrDefault(i => i.MarkdownCategoryId == cat.Model.id);
                if (dbLink == null)
                {
                    dbLink = new MarkdownCategoryDocument(doc.Model.Connection);
                    dbLink.MarkdownCategoryId = cat.Model.id;
                    dbLink.MarkdownDocumentId = doc.Model.id;
                    dbLink.Create();
                }

                if (!cat.Children.Contains(doc))
                {
                    cat.Children.Add(doc);
                }
            }

            // Add/Remove from uncategoried as necessary.
            if (newCategories.Count() == 0)
            {
                if (!Items.Contains(doc))
                {
                    Items.Add(doc);
                }
            }
            else
            {
                if (Items.Contains(doc))
                {
                    Items.Remove(doc);
                }
            }
        }
Beispiel #6
0
        public void OpenOrCreateNoteForItem()
        {
            if (SelectedTreeViewItem == null)
            {
                return;
            }

            IHasMarkdownDocument item = null;

            if (SelectedTreeViewItem is CategoryViewModel)
            {
                item = (SelectedTreeViewItem as CategoryViewModel).Model;
            }
            else if (SelectedTreeViewItem is StoryViewModel)
            {
                item = (SelectedTreeViewItem as StoryViewModel).Model;
            }
            else if (SelectedTreeViewItem is ChapterViewModel)
            {
                item = (SelectedTreeViewItem as ChapterViewModel).Model;
            }
            else if (SelectedTreeViewItem is SceneViewModel)
            {
                item = (SelectedTreeViewItem as SceneViewModel).Model;
            }

            if (item == null)
            {
                return;
            }

            MarkdownDocument doc = null;

            if (item.MarkdownDocumentId.HasValue)
            {
                doc    = new MarkdownDocument(Model.Connection);
                doc.id = item.MarkdownDocumentId.Value;
                doc.Load();
            }
            else
            {
                doc = MarkdownDocumentViewModel.CreateDocForItem(item, Model.id, true, (item as IHasNameProperty).Name);
            }

            if (doc != null)
            {
                MarkdownDocumentViewModel vm = new MarkdownDocumentViewModel(doc, this);
                vm.OpenInWindow();
            }
        }
Beispiel #7
0
        public void Load()
        {
            Items.Clear();

            List <MarkdownCategory>         dbCategories = MarkdownCategory.GetAllMarkdownDocuments(UniverseVm.Model.Connection).Where(i => i.UniverseId == UniverseVm.Model.id).ToList();
            List <MarkdownCategoryDocument> dbCatDocs    = MarkdownCategoryDocument.GetAllMarkdownDocuments(UniverseVm.Model.Connection).ToList();

            // Filter out "special" docs (attached to tickets or files)
            List <MarkdownDocument> dbDocs = MarkdownDocument.GetAllMarkdownDocuments(UniverseVm.Model.Connection).Where(i => i.UniverseId == UniverseVm.Model.id && !i.IsSpecial).ToList();

            List <MarkdownCategoryViewModel> categories = dbCategories.Select(i => new MarkdownCategoryViewModel(i, UniverseVm)).ToList();
            List <MarkdownDocumentViewModel> docs       = dbDocs.Select(i => new MarkdownDocumentViewModel(i, UniverseVm)).ToList();

            // Link up categories.
            foreach (var cat in categories)
            {
                Categories.Add(cat);
                cat.UniverseVm = UniverseVm;
                if (cat.Model.ParentId == null)
                {
                    Items.Add(cat);
                }
                else
                {
                    MarkdownCategoryViewModel parent = categories.Single(i => i.Model.id == cat.Model.ParentId);
                    cat.Parent = parent;
                    parent.Children.Add(cat);
                }

                // Find any documents that belong to this category.
                var catDocs = dbCatDocs.Where(i => i.MarkdownCategoryId == cat.Model.id).ToList();
                foreach (var item in catDocs)
                {
                    MarkdownDocumentViewModel doc = docs.Single(i => i.Model.id == item.MarkdownDocumentId);
                    doc.Parent = cat;
                    cat.Children.Add(doc);
                }
            }

            // Find any documents that are not in a category.
            foreach (var doc in docs.Where(i => i.Parent == null).ToList())
            {
                Items.Add(doc);
            }
        }
Beispiel #8
0
        public EditMarkdownDocumentCategoriesViewModel(Window owner, MarkdownDocumentViewModel document, MarkdownTree tree)
        {
            Owner               = owner;
            MarkdownTree        = tree;
            Document            = document;
            AvailableCategories = new BindingList <MarkdownCategoryViewModel>();
            SelectedCategories  = new BindingList <MarkdownCategoryViewModel>();

            foreach (var category in MarkdownTree.Categories)
            {
                if (category.Children.Contains(Document))
                {
                    SelectedCategories.Add(category);
                }
                else
                {
                    AvailableCategories.Add(category);
                }
            }
        }