public ProjectInBacklogEditViewModel(IEventAggregator eventAgg, ITaskToTextFactory taskToText)
 {
     this.eventAgg    = eventAgg;
     this.taskToText  = taskToText;
     this.SaveCommand =
         new DelegateCommand(Save);
 }
Exemplo n.º 2
0
        public ProjectModule(IEventAggregator eventAgg, ITaskToTextFactory taskToText)
            : base("/project/")
        {
            this.eventAgg = eventAgg;

            this.RequiresAuthentication();

            Get["/create"] = prms =>
            {
                return View["Views/CreateProject"];
            };

            Get["/{id}"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();
                var withRecord = this.AddIconFilePath(Request.Url,project);

                var user =
                   eventAgg.GetEvent<GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return View["Views/Project", new { Auth = user, Project = withRecord }];
            };

            Get["/{id}/board"] = prms =>
            {
                var a = "/project/" + prms.id as string;
                return
                    Response.AsRedirect(a);
            };

            Get["/{id}/edit"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();

                var sprintText = taskToText.Make(project.Sprints);

                var user =
                   eventAgg.GetEvent<GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return View["Views/ProjectEdit"
                    , new
                    {
                        Auth = user
                        , Project = project
                        , SprintText = sprintText
                    }];
            };

            // todo APIに移動すべき
            Post["/{id}/save"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();
                // todo 競合や削除の警告

                var json = this.Request.Body.ToStreamString();
                var jObj = JObject.Parse(json);
                var sprints = taskToText.Make(jObj["edittext"].Value<string>());

                project.Sprints = sprints;
                eventAgg.GetEvent<UpdateProjectEvent>().Publish(project);

                //var user =
                //   eventAgg.GetEvent<GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();
                return
                    Response.AsJson(json, HttpStatusCode.OK);
            };

            Get["/{id}/report"] = prms =>
            {
                var id = (int)prms.id;

                var view =
                    from project in eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrNothing()
                    select View["Views/ProjectReport", new { Project = project }] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };

            Get["/{id}/works"] = prms =>
            {
                var id = (int)prms.id;

                var view =
                    from project in eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrNothing()
                    select View["Views/ProjectWorks", new { Project = project }] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };

            Get["/{id}/kanban"] = prms =>
            {
                // projectid
                var id = (int)prms.id;

                var view =
                    from project in eventAgg.GetEvent<GetProjectEvent>().Get(x => x.Id == id).FirstOrNothing()
                    let withrecord = this.AddIconFilePath(Request.Url, project)
                let tasks =
                        from sprint in withrecord.Sprints
                        from task in sprint.Tasks
                        select task as ITaskWithRecord
                    let backlogTasks =
                        from task in tasks
                        where task.StatusCode == 0
                        select task
                    let readyTasks =
                        from task in tasks
                        where task.StatusCode == 1
                        select task
                    let inProgressTasks =
                        from task in tasks
                        where task.StatusCode == 2
                        select task
                    let doneTasks =
                        from task in tasks
                        where task.StatusCode == 3
                        select task
                    select View["Views/Kanban", new { Project = withrecord, BacklogTasks = backlogTasks.ToArray(), ReadyTasks = readyTasks.ToArray(), InProgressTasks = inProgressTasks.ToArray(), DoneTasks = doneTasks.ToArray()}] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };
        }
Exemplo n.º 3
0
        public ProjectModule(IEventAggregator eventAgg, ITaskToTextFactory taskToText, ISprintToGraphModel sprintToGraphModel)
            : base("/project/")
        {
            this.eventAgg           = eventAgg;
            this.sprintToGraphModel = sprintToGraphModel;

            this.RequiresAuthentication();

            Get["/{id}"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent <GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();
                var withRecord = ToWithRecordsProject(project);

                var user =
                    eventAgg.GetEvent <GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return(View["Views/Project", new { Auth = user, Project = withRecord }]);
            };

            Get["/create"] = prms =>
            {
                return(View["Views/CreateProject"]);
            };

            Get["/{id}/board"] = prms =>
            {
                var a = "/project/" + prms.id as string;
                return
                    (Response.AsRedirect(a));
            };

            Get["/{id}/edit"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent <GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();

                var sprintText = taskToText.Make(project.Sprints);

                var user =
                    eventAgg.GetEvent <GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return(View["Views/ProjectEdit"
                            , new
                            {
                                Auth = user
                                , Project = project
                                , SprintText = sprintText
                            }]);
            };

            Post["/{id}/save"] = prms =>
            {
                var id = prms.id;

                var project =
                    eventAgg.GetEvent <GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();
                // todo 競合や削除の警告

                var json    = this.Request.Body.ToStreamString();
                var jObj    = JObject.Parse(json);
                var sprints = taskToText.Make(jObj["edittext"].Value <string>());

                project.Sprints = sprints;
                eventAgg.GetEvent <UpdateProjectEvent>().Publish(project);

                //var user =
                //   eventAgg.GetEvent<GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();
                return
                    (Response.AsJson(json, HttpStatusCode.OK));
            };

            Get["/{id}/report"] = prms =>
            {
                var id = prms.id;


                var project =
                    eventAgg.GetEvent <GetProjectEvent>().Get(x => x.Id == id).FirstOrDefault();
                var trendChartModel = MakeTrendChartModel(ToWithRecordsProject(project));
                var piChartModel    = MakePiChartModel(trendChartModel);

                var totalValue    = project.Sprints.SelectMany(x => x.Tasks).Where(x => x.Value.HasValue).Sum(x => x.Value.Value);
                var progressValue =
                    project.Sprints.SelectMany(x => x.Tasks).OfType <ITaskWithRecord>()
                    .SelectMany(x => x.Records)
                    .Sum(x => x.Value);
                var toDayPv  = trendChartModel.Pv.Reverse().Where(x => x.Day <= DateTime.Now).Select(x => x.Value).FirstOrDefault();
                var workDays =
                    project.Sprints.Select(sprintToGraphModel.Make)
                    .Aggregate(new GraphModel(), (a, b) => new GraphModel
                {
                    Pv = sprintToGraphModel.Merge(a.Pv, b.Pv),
                    Ev = sprintToGraphModel.Merge(a.Ev, b.Ev),
                    Ac = sprintToGraphModel.Merge(a.Ac, b.Ac),
                }).Pv.Where(x => x.Value != 0).Count();

                return(View["Views/ProjectReport"
                            , new
                            {
                                Project = project,
                                Days = string.Join(",", trendChartModel.Pv.Select(x => string.Format("'{0}'", x.Day.ToString("yyyy/MM/dd"))).ToArray()),
                                Trend = new
                                {
                                    Pv = string.Join(",", trendChartModel.Pv.Select(x => x.Value.ToString()).ToArray()),
                                    Ev = string.Join(",", trendChartModel.Ev.Select(x => x.Value.ToString()).ToArray()),
                                    Ac = string.Join(",", trendChartModel.Ac.Select(x => x.Value.ToString()).ToArray()),
                                },
                                PI = new
                                {
                                    Spi = string.Join(",", piChartModel.Item1.Select(x => x.Value.ToString()).ToArray()),
                                    Cpi = string.Join(",", piChartModel.Item2.Select(x => x.Value.ToString()).ToArray()),
                                },
                                Spi = piChartModel.Item1.Reverse().FirstOrDefault(x => x.Day <= DateTime.Now),
                                Cpi = piChartModel.Item2.Reverse().FirstOrDefault(x => x.Day <= DateTime.Now),
                                Progress = progressValue - toDayPv,
                                Remaining = totalValue - progressValue,
                                Average = (totalValue - progressValue) / workDays,
                            }]);
            };
        }
Exemplo n.º 4
0
        public ProjectModule(
            IDataBaseContext context
            , ITaskToTextFactory taskToText)
            : base("/project/")
        {
            this.RequiresAuthentication();

            Get["/create"] = prms =>
            {
                return View["Views/CreateProject"];
            };

            Get["/{id}"] = prms =>
            {
                var id = prms.id;

                var project =
                    context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrDefault();

                var permission = context.GetAccessProjectPermission(project.Id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var withRecord = this.AddIconFilePath(Request.Url,project);

                var user =
                   context.GetUser(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return View["Views/Project", new { Auth = user, Project = withRecord }];
            };

            Get["/{id}/board"] = prms =>
            {
                var a = "/project/" + prms.id as string;
                return
                    Response.AsRedirect(a);
            };

            Get["/{id}/edit"] = prms =>
            {
                var id = prms.id;

                var project =
                    context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrDefault();

                var permission = context.GetAccessProjectPermission(project.Id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var sprintText = taskToText.Make(project.Sprints);

                var user =
                   context.GetUser(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();

                return View["Views/ProjectEdit"
                    , new
                    {
                        Auth = user
                        , Project = project
                        , SprintText = sprintText
                    }];
            };

            // todo APIに移動すべき
            Post["/{id}/save"] = prms =>
            {
                var id = prms.id;

                var user =
                    from c in this.Context.CurrentUser.ToMaybe()
                    from name in c.UserName.ToMaybe()
                    from u in context.GetUser(x => x.Id == name).FirstOrNothing()
                    select u;

                var project =
                    context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrDefault();

                var permission = context.GetAccessProjectPermission(project.Id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                // todo 競合や削除の警告

                var json = this.Request.Body.ToStreamString();
                var jObj = JObject.Parse(json);
                var sprints = taskToText.Make(jObj["edittext"].Value<string>());

                project.Sprints = sprints;
                context.AddProject(project, user.Return());

                //var user =
                //   eventAgg.GetEvent<GetUserEvent>().Get(u => u.Id == Context.CurrentUser.UserName).FirstOrDefault();
                return
                    Response.AsJson(json, HttpStatusCode.OK);
            };

            Get["/{id}/report"] = prms =>
            {
                var id = (int)prms.id;

                var permission = context.GetAccessProjectPermission(id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var view =
                    from project in context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrNothing()
                    select View["Views/ProjectReport", new { Project = project }] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };

            Get["/{id}/works"] = prms =>
            {
                var id = (int)prms.id;

                var permission = context.GetAccessProjectPermission(id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var view =
                    from project in context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrNothing()
                    select View["Views/ProjectWorks", new { Project = project }] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };

            Get["/{id}/kanban"] = prms =>
            {
                // projectid
                var id = (int)prms.id;

                var permission = context.GetAccessProjectPermission(id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var view =
                    from project in context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrNothing()
                    let withrecord = this.AddIconFilePath(Request.Url, project)
                let tasks =
                        from sprint in withrecord.Sprints
                        from task in sprint.Tasks
                        select task as ITaskWithRecord
                    let backlogTasks =
                        from task in tasks
                        where task.StatusCode == 0
                        select task
                    let readyTasks =
                        from task in tasks
                        where task.StatusCode == 1
                        select task
                    let inProgressTasks =
                        from task in tasks
                        where task.StatusCode == 2
                        select task
                    let doneTasks =
                        from task in tasks
                        where task.StatusCode == 3
                        select task
                    select View["Views/Kanban", new { Project = withrecord, BacklogTasks = backlogTasks.ToArray(), ReadyTasks = readyTasks.ToArray(), InProgressTasks = inProgressTasks.ToArray(), DoneTasks = doneTasks.ToArray()}] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };

            Get["/{id}/member"] = prms =>
            {
                var id = (int)prms.id;

                var permission = context.GetAccessProjectPermission(id);

                if (!IsEnableUser(context, permission))
                    return HttpStatusCode.Forbidden;

                var view =
                    from project in context.GetProjects(x => x.Id == id).Select(p => MyClass.ToWithRecordsProject(context, p)).FirstOrNothing()
                    select View["Views/ProjectMember", new { Project = project }] as object;

                return view.Return(() => Response.AsRedirect("/project/" + id));
            };
        }