Exemplo n.º 1
0
        public HelpDeskViewModel([Import] ScrumFactory.Composition.IEventAggregator aggregator)
        {
            this.aggregator = aggregator;

            aggregator.Subscribe<string>(ScrumFactoryEvent.ConfigChanged, c => {
                if (c == "TicketProjectsEnabled")
                    OnPropertyChanged("PanelPlacement");

            });

            OnLoadCommand = new ScrumFactory.Composition.DelegateCommand(() => { if (NeedRefresh) LoadData(); });

            RefreshCommand = new ScrumFactory.Composition.DelegateCommand(LoadData);

            ShowItemCommand = new ScrumFactory.Composition.DelegateCommand<BacklogItem>(ShowItem);

            AddJobCommand = new ScrumFactory.Composition.DelegateCommand(AddJob);

            delayFilter = new DelayAction(800, new DelayAction.ActionDelegate(() => { ticketsSource.View.Refresh(); }));

            ticketsSource = new System.Windows.Data.CollectionViewSource();
            ticketsSource.Filter += new System.Windows.Data.FilterEventHandler(ticketsSource_Filter);

            NeedRefresh = true;
        }
        public BacklogItemTaskListViewModel([Import] ScrumFactory.Composition.IEventAggregator aggregator)
        {
            this.aggregator = aggregator;

            RefreshCommand = new ScrumFactory.Composition.DelegateCommand(LoadTasks);

            ShowTaskCommand = new ScrumFactory.Composition.DelegateCommand<Task>(ShowTask);

            AddTaskCommand = new ScrumFactory.Composition.DelegateCommand<string>(CanAddTask, s => { AddTask(s == "True"); });
            ConfirmAddTaskCommand = new ScrumFactory.Composition.DelegateCommand(ConfirmAddTask);
            CancelAddTaskCommand = new ScrumFactory.Composition.DelegateCommand(CancelAddTask);

            ShowRepositoryLogCommand = new ScrumFactory.Composition.DelegateCommand<int>(ShowRepositoryLog);

            NeedRefresh = true;
        }
        public ProjectsListViewModel(
            [Import] IEventAggregator aggregator,
            [Import] IProjectsService projectsService,
            [Import] IBackgroundExecutor executor,
            [Import] IDialogService dialogs,
            [Import] IAuthorizationService authorizator)
        {
            this.aggregator = aggregator;
            this.projectsService = projectsService;
            this.executor = executor;
            this.dialogs = dialogs;
            this.authorizator = authorizator;

            projectsViewSource = new System.Windows.Data.CollectionViewSource();
            projectsViewSource.SortDescriptions.Add(new SortDescription("Status", ListSortDirection.Ascending));
            projectsViewSource.SortDescriptions.Add(new SortDescription("TotalDayAllocation", ListSortDirection.Descending));
            projectsViewSource.SortDescriptions.Add(new SortDescription("ProjectNumber", ListSortDirection.Descending));

            projectsViewSource.Filter += new System.Windows.Data.FilterEventHandler(FilteredProjects_Filter);
            delayFilter = new DelayAction(500, new DelayAction.ActionDelegate(() => {
                if (allDataLoaded && FilteredProjects != null) {
                    FilteredProjects.Refresh();
                    SetGroupCount();
                } else {
                    LoadProjectList();
                }
            }));

            aggregator.Subscribe<Project>(ScrumFactoryEvent.ProjectStatusChanged, OnProjectStatusChanged);

            aggregator.Subscribe<Project>(ScrumFactoryEvent.ProjectCreated, OnProjectCreated);

            aggregator.Subscribe<MemberProfile>(ScrumFactoryEvent.SignedMemberChanged,
                m => {
                    ((DelegateCommand)CreateProjectCommand).NotifyCanExecuteChanged();
                    if (m == null) {
                        OnProjectListLoaded(new List<Project>());
                        SelectedProject = null;
                        aggregator.Publish<Project>(ScrumFactoryEvent.ViewProjectDetails, SelectedProject);
                        return;
                    }
                    LoadProjectList();
                    ShowDetailOnInit();
                });

            aggregator.Subscribe<Project>(ScrumFactoryEvent.ViewProjectDetails, p => {
                if (SelectedProject != p)
                    SelectedProject = p;
            });

            aggregator.Subscribe(ScrumFactoryEvent.CreateNewProject, () => {
                dialogs.SelectTopMenu(this);
                OpenCreateProjectWindow();
            });

            aggregator.Subscribe<int>(ScrumFactoryEvent.ProjectArgOnInit, OnProjectArgOnInit);

            OnLoadCommand = new DelegateCommand(() => { if (NeedRefresh) LoadProjectList(); });

            RefreshProjectListCommand = new DelegateCommand(() => { LoadProjectList(); });
            ShowDetailWindowCommand = new DelegateCommand<Project>(p => { ShowDetailWindow(p.ProjectUId); });
            CreateProjectCommand = new DelegateCommand(CanCreateProject, OpenCreateProjectWindow);

            CopyToClipboardCommand = new DelegateCommand(CopyToClipboard);

            LoadMoreCommand = new DelegateCommand(() => { LoadProjectList(false); });

            NeedRefresh = true;
        }
        private void OnProjectListLoaded(ICollection<Project> projects, bool clearList = true)
        {
            NeedRefresh = false;

            if (projects == null) {
                HasMoreToLoad = false;
                return;
            }

            // if return less, then there is no more to load
            // if return more, then is an old version,
            // if returns MAX_PROJECTS_PER_REQUEST, then there is more pages
            HasMoreToLoad = (projects.Count == MAX_PROJECTS_PER_REQUEST);

            // if has no more pages and the filter was empty, all the data has been loaded
            allDataLoaded = (!HasMoreToLoad && string.IsNullOrEmpty(SearchFilterText));

            ShowDetailWindowCommand = null;
            if(clearList)
                this.Projects.Clear();
            foreach (var project in projects) {
                this.Projects.Add(project);
            }
            projectsViewSource.GroupDescriptions.Clear();
            projectsViewSource.Source = Projects;

            SetGroupCount();

            ShowDetailWindowCommand = new DelegateCommand<Project>(p => { ShowDetailWindow(p.ProjectUId); });

            projectsViewSource.GroupDescriptions.Add(new PropertyGroupDescription("Status"));

            // wpf auto selectes the first project....i dont want that
            if(Projects.Count>0)
                autoSelectedProject = Projects[0];
            IsLoadingData = false;
            OnPropertyChanged("FilteredProjects");
        }