Exemplo n.º 1
0
 public StreamTableModel(LocalDbContext db, WindowPageHost host)
 {
     _db   = db;
     _host = host;
     this.DeleteHandler = ReactiveCommand.Create(DeleteStream);
     this.ShowHandler   = ReactiveCommand.Create(ShowStream);
     Observable.Merge(WhenAdded <StreamEntity>(), WhenRemoved <StreamEntity>(), WhenUpdated <StreamEntity>())
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(_ =>
     {
         this.Streams.Clear();
         this.Streams.AddRange(db.Streams.ToList());
     });
     this.Streams.Clear();
     this.Streams.AddRange(db.Streams.ToList());
 }
Exemplo n.º 2
0
        public PageControllerModel(
            PageControllerToken token,
            ModuleActivator activator,
            PageControllerReducer reducer,
            SerialUtil serialUtil,
            MainReducer mainReducer,
            WindowPageHost windowPageHost,
            DatabaseManager databaseManager,
            DatabaseBackupService databaseBackupService
            )
        {
            _activator             = activator;
            _windowPageHost        = windowPageHost;
            _databaseManager       = databaseManager;
            _databaseBackupService = databaseBackupService;
            this._serialUtil       = serialUtil;
            InitHandlers();
            ActivateContent(token);

            this.WhenActivated((c) => {
                mainReducer.Select(state => state.FullscreenMode)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(isFullScreen => this.MenuVisibility = !isFullScreen)
                .DisposeWith(c);
                reducer.Select(state => state.SelectedPage)
                .Where(LambdaHelper.NotNull)
                .WithLatestFrom(reducer.Select(state => state.Controls), LambdaHelper.ToTuple)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(tuple => {
                    var(selectedPage, controlsDict) = tuple;
                    var controls = selectedPage == null
                            ? new List <ButtonConfig>()
                            : controlsDict.GetOrDefault(selectedPage.Id) ?? new List <ButtonConfig>();
                    SetActionButtons(controls);
                })
                .DisposeWith(c);
                _serialUtil.ConnectionStatus
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Select(status => status.IsConnected)
                .Subscribe(status => {
                    this.ReaderMenuText = status
                            ? Localization["Отключить считыватель"]
                            : Localization["Включить считыватель"];
                })
                .DisposeWith(c);
            });
        }
Exemplo n.º 3
0
 public DisciplineTableModel(LocalDbContext db, WindowPageHost host)
 {
     _db   = db;
     _host = host;
     this.DeleteMenuButtonConfig = new ButtonConfig {
         Command = ReactiveCommand.Create(DeleteDiscipline)
     };
     this.ShowMenuButtonConfig = new ButtonConfig {
         Command = ReactiveCommand.Create(ShowDiscipline)
     };
     Observable.Merge(WhenAdded <DisciplineEntity>(), WhenRemoved <DisciplineEntity>(), WhenUpdated <DisciplineEntity>())
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(_ =>
     {
         this.Disciplines.Clear();
         this.Disciplines.AddRange(db.Disciplines.ToList());
     });
     this.Disciplines.Clear();
     this.Disciplines.AddRange(db.Disciplines.ToList());
 }
Exemplo n.º 4
0
 public GroupTableModel(LocalDbContext db, WindowPageHost host)
 {
     _db   = db;
     _host = host;
     this.DeleteMenuButtonConfig = new ButtonConfig {
         Command = new CommandHandler(DeleteGroup)
     };
     this.ShowMenuButtonConfig = new ButtonConfig {
         Command = new CommandHandler(ShowGroup)
     };
     Observable.Merge(WhenAdded <GroupEntity>(), WhenRemoved <GroupEntity>(), WhenUpdated <GroupEntity>())
     .ObserveOnDispatcher(DispatcherPriority.Background)
     .Subscribe(_ =>
     {
         this.Groups.Clear();
         this.Groups.AddRange(db.Groups.ToList());
     });
     this.Groups.Clear();
     this.Groups.AddRange(db.Groups.ToList());
 }
        public SchedulePageModel(WindowPageHost windowPageHost, IPageHost currentHost, LocalDbContext context)
        {
            _windowPageHost = windowPageHost;
            _currentHost    = currentHost;
            _context        = context;
            this.OpenRegistrationHandler       = ReactiveCommand.Create(OpenRegistration);
            this.DeleteMenuHandler             = ReactiveCommand.Create(DeleteSelectedLesson);
            this.EditMenuHandler               = ReactiveCommand.Create(OpenLessonEditForm);
            this.OpenStudentLessonTableHandler = ReactiveCommand.Create(OpenStudentLessonTable);
            this.OpenLessonNotesHandler        = ReactiveCommand.Create(OpenLessonNotes);
            this.ToggleLessonCheckedHandler    = ReactiveCommand.Create(ToggleLessonChecked);
            this.Show = ReactiveCommand.Create(ShowLessons);
            this.WhenAnyValue(model => model.SelectedStream)
            .Subscribe
            (
                stream =>
            {
                List <GroupEntity> groups;
                if (stream == null || stream.Id == -1)
                {
                    groups = context.Groups.ToList();
                }
                else
                {
                    groups = stream.Groups?.ToList() ?? new List <GroupEntity>();
                }

                groups.Insert(0, EmptyGroup);
                this.Groups.Clear();
                this.Groups.AddRange(groups);
                if (this.SelectedGroup == null ||
                    this.Groups.FirstOrDefault(model => this.SelectedGroup.Id == model.Id) != null)
                {
                    this.SelectedGroup = EmptyGroup;
                }
            }
            );
            this.RefreshSubject.AsObservable()
            .Subscribe
            (
                async _ =>
            {
                this.Streams.Clear();
                this.Groups.Clear();
                var streamModels = await context.Streams.ToListAsync();
                streamModels.Insert(0, EmptyStream);         // default value
                this.Streams.AddRange(streamModels);
                var schedules = await context.Schedules.ToListAsync();
                schedules.Insert(0, EmptyScheduleComboboxItem);
                schedules.ForEach(this.Schedules.Add);
                (await context.Groups.ToListAsync()).ForEach(this.Groups.Add);
                this.Groups.Insert(0, EmptyGroup);
                this.SelectedGroup      = EmptyGroup;
                this.SelectedLessonType = this.LessonTypes[0];
                this.SelectedSchedule   = EmptyScheduleComboboxItem;
                this.SelectedStream     = EmptyStream;
                ShowLessons();
            }
            );
            Observable.Merge(
                this.WhenAdded <LessonEntity>(),
                this.WhenRemoved <LessonEntity>(),
                this.WhenUpdated <LessonEntity>()
                ).ObserveOnDispatcher(DispatcherPriority.Background)
            .Subscribe(_ => ShowLessons());
        }
Exemplo n.º 6
0
        public RegistrationPageModel(
            StudentCardService studentCardService,
            PhotoService photoService,
            TabPageHost tabPageHost,
            WindowPageHost windowPageHost,
            LocalDbContext db,
            RegistrationPageToken token,
            MainReducer mainReducer,
            PageControllerReducer reducer
            )
        {
            _tabPageHost            = tabPageHost;
            _windowPageHost         = windowPageHost;
            _db                     = db;
            _token                  = token;
            _mainReducer            = mainReducer;
            this.StudentCardService = studentCardService;
            this.PhotoService       = photoService;
            this.DoRegister         = ReactiveCommand.Create(() => {
                if (this.AllStudentsMode)
                {
                    foreach (IStudentViewModel selectedStudent in this.SelectedStudents.ToList())
                    {
                        RegisterExtStudent(selectedStudent.Student);
                    }
                }
                else
                {
                    Register();
                }
            });
            this.DoUnRegister             = ReactiveCommand.Create(UnRegister);
            this.OpenStudentLessonHandler = ReactiveCommand.Create(() =>
                                                                   OpenLesson(this.SelectedStudentLessonNote?.Note?.StudentLesson?.Lesson));

            this.ShowStudent = ReactiveCommand.Create(() => {
                var selectedStudent      = _selectedStudent;
                var studentViewPageToken = new StudentViewPageToken("Студент", selectedStudent);
                tabPageHost.AddPageAsync <StudentViewPageModule, StudentViewPageToken>(studentViewPageToken);
            });
            this.AddStudentNote = ReactiveCommand.Create(() => {
                var noteFormToken = new NoteListFormToken("Заметки", () => new StudentLessonNote()
                {
                    StudentLesson = _selectedStudentLesson.StudentLesson,
                    EntityId      = _selectedStudentLesson.StudentLesson.Id
                }, _selectedStudentLesson.StudentLesson.Notes);
                windowPageHost.AddPageAsync <NoteListFormModule, NoteListFormToken>(noteFormToken);
            });
            this.ToggleAllStudentTable = new ButtonConfig {
                Command = ReactiveCommand.Create(() => this.AllStudentsMode = !this.AllStudentsMode),
                Text    = Localization["Все студенты"]
            };
            this.AllStudentsFilter = (o, s) => {
                var student      = ((IStudentViewModel)o).Student;
                var alreadyAdded =
                    IsStudentAlreadyRegistered(RegisteredStudents.Cast <StudentLessonInfoViewModel>(), student) ||
                    IsStudentAlreadyRegistered(LessonStudents.Cast <StudentLessonInfoViewModel>(), student);
                if (alreadyAdded)
                {
                    return(false);
                }
                s = s.ToLowerInvariant();
                return(student.FirstName != null &&
                       student.FirstName.ToLowerInvariant()
                       .Contains(s) ||
                       student.LastName != null &&
                       student.LastName.ToLowerInvariant()
                       .Contains(s) ||
                       student.SecondName != null &&
                       student.SecondName.ToLowerInvariant()
                       .Contains(s));
            };

            InitTableConfigs();
            Init(token.Lesson);
            this.WhenActivated(disposable => {
                this.WhenAnyValue(model => model.TimerState)
                .Where(LambdaHelper.NotNull)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(state => {
                    this.TimerString = $"{state.TimeLeft:hh\\:mm\\:ss}/{state.CurrentTime:HH:mm:ss}";
                }).DisposeWith(disposable);
                this.WhenAnyValue(model => model.Lesson)
                .Where(LambdaHelper.NotNull)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(entity => {
                    var groupName  = entity.Group?.Name ?? entity.Stream.Name;
                    var lessonInfo =
                        $"{Localization["common.lesson.type." + entity.LessonType]}: {entity.Order}/{entity.GetLessonsCount()}";
                    this.LessonInfoState = new LessonInfoState {
                        GroupName  = groupName,
                        LessonInfo = lessonInfo,
                        Date       = entity.Date?.ToString("dd.MM.yyyy"),
                        Time       =
                            $"[{entity.Schedule.OrderNumber}] {entity.Schedule.Begin:hh\\:mm} - {entity.Schedule.End:hh\\:mm}"
                    };
                }).DisposeWith(disposable);
                this.WhenAnyValue(model => model.AllStudentsMode)
                .Throttle(TimeSpan.FromMilliseconds(100))
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(b => {
                    this.ToggleAllStudentTable.Text = b ? Localization["Занятие"] : Localization["Все студенты"];
                    if (!b || this.AllStudents.Count != 0)
                    {
                        return;
                    }
                    var studentViewModels = db.Students
                                            .Include(model => model.Groups)
                                            .ToList() // create query and load
                                            .Select(model => new StudentViewModel(model))
                                            .ToList();
                    this.AllStudents.AddRange(studentViewModels);
                }).DisposeWith(disposable);

                this.WhenAnyValue(model => model.IsLessonChecked)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(b => {
                    if (this.Lesson == null)
                    {
                        return;
                    }

                    this.Lesson.Checked = b;
                    this._db.ThrottleSave();
                }).DisposeWith(disposable);
                this.LessonStudentsTableConfig.SelectedItem
                .Where(LambdaHelper.NotNull)
                .Merge(this.RegisteredStudentsTableConfig.SelectedItem.AsObservable().Where(LambdaHelper.NotNull))
                .Cast <StudentLessonInfoViewModel>()
                .Do(o => this._selectedStudentLesson = o)
                .Select(o => o.StudentLesson.Student)
                .Merge(this.AllStudentsTableConfig.SelectedItem.Where(LambdaHelper.NotNull))
                .Throttle(TimeSpan.FromMilliseconds(200))
                .Subscribe
                (
                    async o => {
                    var studentEntity = o as StudentEntity;
                    _selectedStudent  = studentEntity;
                    await UpdateDescription(studentEntity);
                    await UpdateStudentLessonNotes(studentEntity);
                }
                ).DisposeWith(disposable);

                this.WhenRemoved <LessonEntity>()
                .Where(entities => entities.Any(entity => entity.Id == this.Lesson?.Id))
                .Subscribe(_ => token.Deactivate())
                .DisposeWith(disposable);
                this.WhenRemoved <StudentLessonNote>()
                .Merge(this.WhenAdded <StudentLessonNote>())
                .Merge(this.WhenUpdated <StudentLessonNote>())
                .Where(notes => this._selectedStudent != null &&
                       notes.Any(note => note.StudentLesson._StudentId == this._selectedStudent.Id))
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(_ => UpdateStudentLessonNotes(this._selectedStudent));
                this.StudentCardService.ReadStudentCard.Subscribe(ReadStudentData);
            });
            GetControls()
            .ToObservable()
            .TakeUntil(DestroySubject)
            .Subscribe(controls =>
            {
                reducer.Dispatch(new RegisterControlsAction(token, controls));
            });
        }
        public StudentViewPageModel(
            StudentViewPageToken token,
            PageControllerReducer reducer,
            TabPageHost host,
            WindowPageHost windowPageHost,
            PhotoService photoService,
            LocalDbContext context
            )
        {
            _host           = host;
            _windowPageHost = windowPageHost;
            _photoService   = photoService;
            _context        = context;
            this.AddAttestationButtonConfig = new ButtonConfig {
                Command = ReactiveCommand.Create(AddAttestation),
                Text    = "+"
            };
            this.AddExamButtonConfig = new ButtonConfig {
                Command = ReactiveCommand.Create(AddExam),
                Text    = "+"
            };
            this.OpenExternalLessonHandler = ReactiveCommand.Create(() => {
                var selectedExternalLesson = this.SelectedExternalLesson;
                if (selectedExternalLesson == null)
                {
                    return;
                }

                host.AddPageAsync(new RegistrationPageToken("Регистрация", selectedExternalLesson.Lesson));
            });
            this.OpenStudentLessonHandler = ReactiveCommand.Create(() =>
                                                                   OpenLesson(this.SelectedStudentLessonNote?.Note.StudentLesson.Lesson));
            Initialize(token.Student);
            this.WhenActivated(c => {
                this.WhenAnyValue(model => model.Student)
                .Where(LambdaHelper.NotNull)
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe
                (
                    student => {
                    UpdateExternalLessons(student);
                    UpdateStudentLessonNotes(student);
                    UpdateStudentNotes(student);
                }
                ).DisposeWith(c);
                this.WhenAnyValue(model => model.SelectedStream).Subscribe(OnSelectedStreamUpdate).DisposeWith(c);
                this.WhenAnyValue(model => model.SelectedGroup).Subscribe(OnSelectedGroupUpdate).DisposeWith(c);
                this.WhenAdded <StudentLessonNote>().Merge(this.WhenRemoved <StudentLessonNote>())
                .Merge(WhenUpdated <StudentLessonNote>())
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(_ => UpdateStudentLessonNotes(this.Student)).DisposeWith(c);
                this.WhenAdded <StudentLessonEntity>()
                .Merge(this.WhenRemoved <StudentLessonEntity>())
                .Merge(WhenUpdated <StudentLessonEntity>())
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(_ => {
                    OnSelectedGroupUpdate(this.SelectedGroup);
                    UpdateExternalLessons(this.Student);
                    UpdateStudentLessonNotes(this.Student);
                }).DisposeWith(c);
                this.WhenAdded <StudentNote>()
                .Merge(this.WhenRemoved <StudentNote>())
                .Merge(WhenUpdated <StudentNote>())
                .ObserveOnDispatcher(DispatcherPriority.Background)
                .Subscribe(_ => UpdateStudentNotes(this.Student)).DisposeWith(c);
            });
            reducer.Dispatch(new RegisterControlsAction(token, GetControls()));
        }