Skip to content

Commit

Permalink
Implement async data loading to teacher discipline page, resolves #5 #21
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaxXx committed Jun 28, 2023
1 parent 965c587 commit 7655481
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
12 changes: 7 additions & 5 deletions grade_app/TeacherDisciplinePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core"
xmlns:grade_app="clr-namespace:grade_app"
x:DataType="grade_app:TeacherDisciplinePage"
android:TabbedPage.ToolbarPlacement="Bottom"
Title="{Binding TeacherDiscipline.Discipline.SubjectName}">
android:TabbedPage.ToolbarPlacement="Bottom">
<ContentPage Title="Баллы"
IconImageSource="{OnPlatform iOS=baseline_assignment_black_24pt, Android=ic_assignment_black_24dp.xml}">
<StackLayout>
Expand All @@ -25,15 +24,16 @@
ItemsSource="{Binding subModulePickerItems}"
ItemDisplayBinding="{Binding Name}"
SelectedIndexChanged="SubmodulePicker_SelectedIndexChanged"
IsVisible="{Binding TeacherDiscipline.Discipline.IsMapCreated}"
IsVisible="{Binding disciplineInfo.IsDisciplineMapCreated}"
FontSize="{StaticResource MySubtitle}"/>
<ActivityIndicator x:Name="activityIndicatorRates" IsRunning="False" IsVisible="False"/>
<ListView x:Name="StudentSubmoduleList"
ItemsSource="{Binding FilteredGroupedRatesStudentsList}"
CachingStrategy="RecycleElement"
IsGroupingEnabled="True"
HasUnevenRows="True"
SelectionMode="None"
IsVisible="{Binding TeacherDiscipline.Discipline.IsMapCreated}">
IsVisible="{Binding disciplineInfo.IsDisciplineMapCreated}">
<ListView.ItemTemplate>
<DataTemplate x:DataType="grade_app:StudentSubmoduleItem">
<ViewCell
Expand Down Expand Up @@ -67,7 +67,7 @@
Focused="Entry_Focused"
Unfocused="Entry_Unfocused"
FontSize="{StaticResource MySubtitle}"
IsEnabled="{Binding Source={RelativeSource AncestorType={x:Type grade_app:TeacherDisciplinePage}}, Path=DisciplineNotFrozen}"
IsEnabled="{Binding Source={RelativeSource AncestorType={x:Type grade_app:TeacherDisciplinePage}}, Path=disciplineInfo.DisciplineNotFrozen}"
x:Name="vsEntry"/>
<Label Grid.Row="0"
Grid.Column="2"
Expand Down Expand Up @@ -113,6 +113,7 @@
ItemDisplayBinding="{Binding Name}"
SelectedIndexChanged="LessonPicker_SelectedIndexChanged"
FontSize="{StaticResource MySubtitle}"/>
<ActivityIndicator x:Name="activityIndicatorJournal" IsRunning="False" IsVisible="False"/>
<ListView ItemsSource="{Binding FilteredGroupedJournalStudentsList}"
IsGroupingEnabled="True"
HasUnevenRows="True"
Expand Down Expand Up @@ -189,6 +190,7 @@
IconImageSource="{OnPlatform iOS=baseline_info_outline_black_24pt, Android=baseline_info_outline_24.xml}">
<ScrollView>
<StackLayout>
<ActivityIndicator x:Name="activityIndicatorInfo" IsRunning="False" IsVisible="False"/>
<Label FormattedText="{Binding MoreInfo}" LineHeight="1.5"/>
</StackLayout>
</ScrollView>
Expand Down
77 changes: 56 additions & 21 deletions grade_app/TeacherDisciplinePage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -19,7 +20,7 @@ public partial class TeacherDisciplinePage : TabbedPage
public ObservableCollection<DisGroup> FilteredGroupedRatesStudentsList { get; private set; } = new ObservableCollection<DisGroup>();
public string subModuleFilter { get; private set; } = "ВСЕ";

public bool DisciplineNotFrozen { get; private set; }
public DisciplineInfo disciplineInfo { get; private set; } = new DisciplineInfo();

public TeacherJournal TeacherJournal { get; private set; }
public ObservableCollection<LessonPickerItem> LessonPickerItems { get; private set; } = new ObservableCollection<LessonPickerItem>();
Expand All @@ -28,52 +29,61 @@ public partial class TeacherDisciplinePage : TabbedPage

public string lessonFilter { get; private set; } = "ВСЕ";

public string teachersStr { get; private set; }

public FormattedString MoreInfo { get; private set; } = new FormattedString();

public TeacherDisciplinePage(long id, List<Teacher> teachers)
{
InitializeComponent();

teachersStr = string.Join("\n", teachers.Select(t => t.FullName()));
TeacherDiscipline = App.API.TeacherGetDiscipline(id);
DisciplineNotFrozen = !TeacherDiscipline.Discipline.Frozen;
_ = LoadData(id, teachers);

//Must be at the end!!!
BindingContext = this;
}

private async Task LoadData(long id, List<Teacher> teachers)
{
activityIndicatorRates.IsRunning = activityIndicatorRates.IsVisible = true;
activityIndicatorJournal.IsRunning = activityIndicatorJournal.IsVisible = true;
activityIndicatorInfo.IsRunning = activityIndicatorInfo.IsVisible = true;
TeacherDiscipline = await App.API.TeacherGetDiscipline(id);
Title = TeacherDiscipline.Discipline.SubjectName;
disciplineInfo.DisciplineNotFrozen = !TeacherDiscipline.Discipline.Frozen;
disciplineInfo.IsDisciplineMapCreated = TeacherDiscipline.Discipline.IsMapCreated;
FillSubModulePicker();
if(!TeacherDiscipline.Discipline.IsMapCreated)
if (!TeacherDiscipline.Discipline.IsMapCreated)
{
WarningLabel.Text = "Для дисциплины не создана учебная карта";
WarningLabel.IsVisible = true;
}
if(TeacherDiscipline.Discipline.Frozen)
if (TeacherDiscipline.Discipline.Frozen)
{
WarningLabel.Text = "Дисциплина подписана, выставление баллов невозможно";
WarningLabel.IsVisible = true;
}
else if(TeacherDiscipline.Discipline.Milestone > 0 & TeacherDiscipline.Discipline.Milestone < 4)
else if (TeacherDiscipline.Discipline.Milestone > 0 & TeacherDiscipline.Discipline.Milestone < 4)
{
WarningLabel.Text = "Семестр завершен, выставление баллов запрещено";
WarningLabel.IsVisible = true;
}
if(TeacherDiscipline.Discipline.Milestone > 0 & TeacherDiscipline.Discipline.Milestone < 4)
if (TeacherDiscipline.Discipline.Milestone > 0 & TeacherDiscipline.Discipline.Milestone < 4)
{
MilestoneLabel.Text = $"Дисциплина находится на этапе №{ TeacherDiscipline.Milestone.Id + 1 } \"{ TeacherDiscipline.Milestone.Name }\"";
MilestoneLabel.Text = $"Дисциплина находится на этапе №{TeacherDiscipline.Milestone.Id + 1} \"{TeacherDiscipline.Milestone.Name}\"";
MilestoneLabel.IsVisible = true;
}
activityIndicatorRates.IsRunning = activityIndicatorRates.IsVisible = false;

TeacherJournal = App.API.TeacherGetDisciplineJournal(id);
TeacherJournal = await App.API.TeacherGetDisciplineJournal(id);
FillLessonPicker();
if (LessonPickerItems.Count > 0)
LessonPicker.SelectedIndex = 0;
activityIndicatorJournal.IsRunning = activityIndicatorJournal.IsVisible = false;

FillMoreInfo();


//Must be at the end!!!
BindingContext = this;
FillMoreInfo(teachers);
activityIndicatorInfo.IsRunning = activityIndicatorInfo.IsVisible = false;
}

private void FillMoreInfo()
private void FillMoreInfo(List<Teacher> teachers)
{
if (TeacherDiscipline.Discipline == null)
return;
Expand All @@ -89,7 +99,7 @@ private void FillMoreInfo()
AddLineToInfo("Этап", TeacherDiscipline.Milestone == null ? "" : $"{TeacherDiscipline.Milestone.Id + 1} \"{TeacherDiscipline.Milestone.Name}\"");

AddLineToInfo("Группы", TeacherDiscipline.Groups == null ? "" : ("\n" + string.Join("\n", TeacherDiscipline.Groups.Select(g => $"Группа {g.Value.GroupNum} - {g.Value.SpecName}"))));
AddLineToInfo("Преподаватели", "\n" + teachersStr);
AddLineToInfo("Преподаватели", "\n" + string.Join("\n", teachers.Select(t => t.FullName())));
}
private void AddLineToInfo(string title, string value)
{
Expand Down Expand Up @@ -151,7 +161,7 @@ private void SubmodulePicker_SelectedIndexChanged(object sender, EventArgs e)
WarningLabel.IsVisible = false;
}
var isInOurMilestone = (TeacherDiscipline.Milestone.Mask & TeacherDiscipline.Modules[smi.ModuleID].Submodules.First(sm => sm.Id == smi.ID).MilestoneMask) > 0;
DisciplineNotFrozen = !TeacherDiscipline.Discipline.Frozen && isInOurMilestone;
disciplineInfo.DisciplineNotFrozen = !TeacherDiscipline.Discipline.Frozen && isInOurMilestone;
PrepareRatesStudentsList();
}

Expand Down Expand Up @@ -291,7 +301,7 @@ async private void AddLesson_Clicked(object sender, EventArgs e)
}
else
{
TeacherJournal = App.API.TeacherGetDisciplineJournal(TeacherJournal.Discipline.Id);
TeacherJournal = await App.API.TeacherGetDisciplineJournal(TeacherJournal.Discipline.Id);
FillLessonPicker();
LessonPicker.SelectedIndex = LessonPickerItems.Count - 1;
}
Expand Down Expand Up @@ -455,6 +465,31 @@ private void LessonItem_Tapped(object sender, EventArgs e)
if (checkBox != null)
checkBox.IsChecked = !checkBox.IsChecked;
}

public class DisciplineInfo : INotifyPropertyChanged
{
private bool disciplineNotFrozen;
private bool isDisciplineMapCreated;

public event PropertyChangedEventHandler PropertyChanged;

public bool DisciplineNotFrozen
{
get => disciplineNotFrozen; set
{
disciplineNotFrozen = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DisciplineNotFrozen)));
}
}
public bool IsDisciplineMapCreated
{
get => isDisciplineMapCreated; set
{
isDisciplineMapCreated = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsDisciplineMapCreated)));
}
}
}
}

public class StudentSubmoduleItem
Expand Down

0 comments on commit 7655481

Please sign in to comment.