/// <summary> /// Makes child nodes for each file in the assignment /// </summary> private void BuildFileTreeView(RelevantAssignment ra, TreeViewItem tvi, IList <RelevantAssignment.AssignmentStream> files) { // make child nodes for each file in the assignment foreach (RelevantAssignment.AssignmentStream stream in files) { // If the assignment is a critical review then it can potentially have both original // documents and reviewed documents as streams within it. In the case where we're // loading, we want to show all of these. // However, in the case where we're saving we cannot overwrite the originals. Rather, // we can only save reviews. So for that save case we should show only originals and // label them in a way that implies that a save submits a review for that document. if (!m_saveMode) { TreeViewItem tviChild = new TreeViewItem(); tviChild.Header = stream.Name; if (ra.IsCriticalReview) { // Mark files as originals or reviews if (stream.IsOriginalForReview) { tviChild.Header += " (author's original file)"; } else { tviChild.Header += " (your review file)"; } } tviChild.Tag = stream; tvi.Items.Add(tviChild); } else if (stream.IsOriginalForReview) { TreeViewItem tviChild = new TreeViewItem(); tviChild.Header = "Save as review for " + stream.AuthorName; tviChild.Tag = stream; tvi.Items.Add(tviChild); } } }
private void OKButton_Click_Open(object sender, RoutedEventArgs e) { // Don't do anything if there's nothing selected in the tree if (null == MainTreeView.SelectedItem || null == (MainTreeView.SelectedItem as Control).Tag) { return; } // Get a reference to the workspace Logic.Workspace ws = Core.App.Workspace.DrawingCanvasReference.GetWorkspace(); // Get the selected tree view item Control selectedItem = MainTreeView.SelectedItem as Control; // Get the assignment stream for the selected item RelevantAssignment.AssignmentStream ras = (MainTreeView.SelectedItem as TreeViewItem).Tag as RelevantAssignment.AssignmentStream; if (null != ras) { m_state.CurrentAssignment = ras.Parent; if (0 == ras.Length) { MessageBox.Show("Assignment has yet to be submitted. You may save your work to OSBLE to " + "submit the first version for this assignment."); } else { // Hide the buttons and show the progress bar OKButton.Visibility = System.Windows.Visibility.Collapsed; CancelButton.Visibility = System.Windows.Visibility.Collapsed; MainProgressBar.Visibility = System.Windows.Visibility.Visible; try { ws.Load(ras); } catch (Exception) { MessageBox.Show("File could not be loaded. It is recommended that you try downloading " + "the file from the OSBLE web interface."); } // Tell the drawing canvas to update stream positions now that everything is loaded Core.App.Workspace.DrawingCanvas.UpdateAllStreamLocations(); } this.DialogResult = true; } else { RelevantAssignment ra = (MainTreeView.SelectedItem as TreeViewItem).Tag as RelevantAssignment; // If there's not an assignment associated with this node then we just ignore if (null == ra) { return; } if (0 == (MainTreeView.SelectedItem as TreeViewItem).Items.Count) { if (AssignmentTypes.Basic == ra.ActualAssignment.Type) { m_state.CurrentAssignment = ra; // 0 files for a basic assignment means the user has yet to submit anything MessageBox.Show("Assignment has yet to be submitted. You may save your work to OSBLE to " + "submit the first version for this assignment."); } else if (AssignmentTypes.CriticalReview == ra.ActualAssignment.Type) { // 0 files for a critical review means that no one has submitted files to review MessageBox.Show("You have selected a critical review assignment for which there are " + "currently no files available. Files for this assignment will become available " + "after the individuals who you are assigned to review submit their files."); return; } else { // Else we ignore it because they have to choose a child item return; } } else if (1 == (MainTreeView.SelectedItem as TreeViewItem).Items.Count) { // If there's only one option under this node then just load that MainTreeView.SelectItem((MainTreeView.SelectedItem as TreeViewItem).Items[0]); OKButton_Click_Open(sender, e); return; } else { // Else we ignore it because they have to choose a child item MessageBox.Show("You have selected a assignment that has multiple files within it. Please " + "select a specific file to open."); return; } } this.DialogResult = true; }
/// <summary> /// Must be invoked on the UI thread. /// </summary> private void AssignmentGetComplete(object sender, EventArgs e) { RelevantAssignment.RelevantAssignmentEventArgs args = e as RelevantAssignment.RelevantAssignmentEventArgs; RelevantAssignment ra = sender as RelevantAssignment; // In earlier versions I tried out not having a parent node for each course but // 1. The user should see what course the assignments belong to // 2. Having to put the course name in each individual assignment node made it looked cluttered // So each course gets its own parent node. Under this node will be assignment nodes and under // the assignment nodes will be assignment files (and maybe some other items relevant to that // assignment) TreeViewItem courseNode; if (!m_courseNodes.ContainsKey(ra.CourseName)) { courseNode = new TreeViewItem() { Header = ra.CourseName }; MainTreeView.Items.Add(courseNode); m_courseNodes.Add(ra.CourseName, courseNode); // We want all nodes expanded by default courseNode.IsExpanded = true; } else { courseNode = m_courseNodes[ra.CourseName]; } // Build the node for the assignment TreeViewItem tvi = new TreeViewItem(); string type = ra.ActualAssignment.Type.ToString(); switch (ra.ActualAssignment.Type) { case AssignmentTypes.CriticalReview: type = "Critical Review"; break; case AssignmentTypes.CriticalReviewDiscussion: type = "Critical Review Discussion"; break; //keep default name default: type = ra.ActualAssignment.Type.ToString(); break; } tvi.Header = string.Format("{0}\nType: {1}\nDue Date: {2}", ra.Name, type, ra.ActualAssignment.DueDate.ToString("f") ); tvi.Tag = ra; tvi.IsExpanded = true; // Put it under the course node, in sorted order by due date InsertAssignmentNodeSorted(courseNode, tvi, ra.ActualAssignment.DueDate); // Critical review discussions are special as they need a link into OSBLE. We // only show them in open mode (they are hidden in save mode). if (!m_saveMode && AssignmentTypes.CriticalReviewDiscussion == ra.ActualAssignment.Type) { StackPanel sp = new StackPanel(); HyperlinkButton hb = new HyperlinkButton(); string url = string.Format( "{0}/Account/TokenLogin?authToken={1}&destinationUrl=/AssignmentDetails/{2}", s_URLPrefix, ra.LastAuthToken, ra.ActualAssignment.ID.ToString()); hb.NavigateUri = new Uri(url); hb.Content = "Go to this assignment in OSBLE"; sp.Children.Add(hb); // Every assignment node must have the assignment object as its tag sp.Tag = ra; TreeViewItem ti = new TreeViewItem(); ti.Header = sp; tvi.Items.Add(ti); } // Now make child nodes for each file in the assignment foreach (RelevantAssignment.AssignmentStream stream in args.Files) { // If the assignment is a critical review then it can potentially have both original // documents and reviewed documents as streams within it. In the case where we're // loading, we want to show all of these. // However, in the case where we're saving we cannot overwrite the originals. Rather, // we can only save reviews. So for that save case we should show only originals and // label them in a way that implies that a save submits a review for that document. if (!m_saveMode) { TreeViewItem tviChild = new TreeViewItem(); tviChild.Header = stream.Name; if (ra.IsCriticalReview) { // Mark files as originals or reviews if (stream.IsOriginalForReview) { tviChild.Header += " (author's original file)"; } else { tviChild.Header += " (your review file)"; } } tviChild.Tag = stream; tvi.Items.Add(tviChild); } else if (stream.IsOriginalForReview) { TreeViewItem tviChild = new TreeViewItem(); tviChild.Header = "Save as review for " + stream.AuthorName; tviChild.Tag = stream; tvi.Items.Add(tviChild); } } if (0 == System.Threading.Interlocked.Decrement(ref m_refreshRemaining)) { UpdateComplete(); } }