Beispiel #1
0
        public static List<ActivityDay> GetCalendarDaysFor(int? period/*0=yearly, 1=monthly and 2=weekly*/)
        {
            var days = new List<ActivityDay>();
            //var calendar = new ActivityCalendar();
                var calendarYear = new GregorianCalendar();
                switch (period)
                {
                    case 0:

                        var dayNumber=(int)DateTime.Now.DayOfWeek;
                        var weekDay = DateTime.Now.AddDays(-dayNumber);

                        for (int i=0;i<7;i++)
                        {

                            days.Add(new ActivityDay {
                                Date = weekDay,
                                Name = calendarYear.GetDayOfWeek(weekDay).ToString(),
                                Status=true,
                                ActivityStatus = calendarYear.GetDayOfWeek(weekDay) == DayOfWeek.Friday ?
                                DayStatus.Holiday
                                :DayStatus.Active});
                            weekDay=weekDay.AddDays(1);
                        }
                        break;
                    case 1:

                        var daysInMonth=calendarYear.GetDaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                        for (int day = 1; day <= daysInMonth;day++ )
                        {
                            var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day);
                            days.Add(new ActivityDay
                            {
                                Date = date,
                                Name = calendarYear.GetDayOfWeek(date).ToString(),
                                Status = true,
                                ActivityStatus = calendarYear.GetDayOfWeek(date) ==
                                DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active
                            });
                        }
                        break;
                    default:

                        var daysInYr=calendarYear.GetDaysInYear(DateTime.Now.Year);
                        var startOfYr = new DateTime(DateTime.Now.Year, 1, 1);
                        for (int day = 0; day < daysInYr; day++)
                        {
                            var dateOfYr = new ActivityDay {Date=startOfYr.AddDays(day) };
                            dateOfYr.Name = calendarYear.GetDayOfWeek(dateOfYr.Date).ToString();
                            dateOfYr.Status = true;
                            dateOfYr.ActivityStatus = calendarYear.GetDayOfWeek(dateOfYr.Date) == DayOfWeek.Friday ? DayStatus.Holiday : DayStatus.Active;
                            days.Add(dateOfYr);

                        }

                        break;
                }
                return days;
        }
        public string GetHTMLLog(string name)
        {
            List <SparkleCommit> commits = GetLog (name);

                        List <ActivityDay> activity_days = new List <ActivityDay> ();

            foreach (SparkleCommit commit in commits) {

                GetAvatar (commit.UserEmail, 32);

                bool commit_inserted = false;
                foreach (ActivityDay stored_activity_day in activity_days) {

                    if (stored_activity_day.DateTime.Year  == commit.DateTime.Year &&
                        stored_activity_day.DateTime.Month == commit.DateTime.Month &&
                        stored_activity_day.DateTime.Day   == commit.DateTime.Day) {

                        stored_activity_day.Add (commit);
                        commit_inserted = true;
                        break;

                    }

                }

                if (!commit_inserted) {

                        ActivityDay activity_day = new ActivityDay (commit.DateTime);
                        activity_day.Add (commit);
                        activity_days.Add (activity_day);

                }

            }

            StreamReader reader;

            reader = new StreamReader (Defines.PREFIX + "/share/sparkleshare/html/event-log.html");
            string event_log_html = reader.ReadToEnd ();
            reader.Close ();

            reader = new StreamReader (Defines.PREFIX + "/share/sparkleshare/html/day-entry.html");
            string day_entry_html = reader.ReadToEnd ();
            reader.Close ();

            reader = new StreamReader (Defines.PREFIX + "/share/sparkleshare/html/event-entry.html");
            string event_entry_html = reader.ReadToEnd ();
            reader.Close ();

            string event_log = "";

            foreach (ActivityDay activity_day in activity_days) {

                string event_entries = "";

                foreach (SparkleCommit change_set in activity_day) {

                    string event_entry = "<dl>";

                    if (change_set.Edited.Count > 0) {

                        event_entry += "<dt>Edited</dt>";

                        foreach (string file_path in change_set.Edited) {

                            if (File.Exists (SparkleHelpers.CombineMore (SparklePaths.SparklePath ,name , file_path))) {

                                event_entry += "<dd><a href='#'>" + file_path + "</a></dd>";

                            } else {

                                event_entry += "<dd>" + SparkleHelpers.CombineMore (SparklePaths.SparklePath, name, file_path) + "</dd>";

                            }

                        }

                    }

                    if (change_set.Added.Count > 0) {

                        event_entry += "<dt>Added</dt>";

                        foreach (string file_path in change_set.Added) {

                            if (File.Exists (SparkleHelpers.CombineMore (SparklePaths.SparklePath ,name , file_path))) {

                                event_entry += "<dd><a href='#'>" + file_path + "</a></dd>";

                            } else {

                                event_entry += "<dd>" + SparkleHelpers.CombineMore (SparklePaths.SparklePath ,name , file_path) + "</dd>";

                            }

                        }

                    }

                    if (change_set.Deleted.Count > 0) {

                        event_entry += "<dt>Deleted</dt>";

                        foreach (string file_path in change_set.Deleted) {

                            if (File.Exists (SparkleHelpers.CombineMore (SparklePaths.SparklePath ,name , file_path))) {

                                event_entry += "<dd><a href='#'>" + file_path + "</a></dd>";

                            } else {

                                event_entry += "<dd>" + SparkleHelpers.CombineMore (SparklePaths.SparklePath ,name , file_path) + "</dd>";

                            }

                        }

                    }
            Console.WriteLine(GetAvatar (change_set.UserEmail, 32));
                    event_entry += "</dl>";
                    event_entries += event_entry_html.Replace ("<!-- $event-entry-content -->", event_entry)
                        .Replace ("<!-- $event-user-name -->", change_set.UserName)
                        .Replace ("<!-- $event-avatar-url -->", "file://" +GetAvatar (change_set.UserEmail, 32) )
                        .Replace ("<!-- $event-time -->", change_set.DateTime.ToString ("H:mm"));

                }

                string day_entry = "";

                DateTime today = DateTime.Now;
                DateTime yesterday = DateTime.Now.AddDays (-1);

                if (today.Day   == activity_day.DateTime.Day &&
                    today.Month == activity_day.DateTime.Month &&
                    today.Year  == activity_day.DateTime.Year) {

                    day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "<b>Today</b>");

                } else if (yesterday.Day   == activity_day.DateTime.Day &&
                           yesterday.Month == activity_day.DateTime.Month &&
                           yesterday.Year  == activity_day.DateTime.Year) {

                    day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->", "<b>Yesterday</b>");

                } else {

                    day_entry = day_entry_html.Replace ("<!-- $day-entry-header -->",
                        "<b>" + activity_day.DateTime.ToString ("ddd MMM d, yyyy") + "</b>");

                }

                event_log += day_entry.Replace ("<!-- $day-entry-content -->", event_entries);

            }

            string html = event_log_html.Replace ("<!-- $event-log-content -->", event_log);

            return html;
        }
Beispiel #3
0
        private ScrolledWindow CreateEventLog()
        {
            List <SparkleCommit> commits = new List <SparkleCommit> ();

            foreach (SparkleRepo repo in SparkleShare.Controller.Repositories) {

                // Get commits from the repository
                if (repo.LocalPath.Equals (LocalPath)) {

                    commits = repo.GetCommits (25);
                    break;

                }

            }

            List <ActivityDay> activity_days = new List <ActivityDay> ();

            foreach (SparkleCommit commit in commits) {

                bool commit_inserted = false;
                foreach (ActivityDay stored_activity_day in activity_days) {

                    if (stored_activity_day.DateTime.Year  == commit.DateTime.Year &&
                        stored_activity_day.DateTime.Month == commit.DateTime.Month &&
                        stored_activity_day.DateTime.Day   == commit.DateTime.Day) {

                        stored_activity_day.Add (commit);
                        commit_inserted = true;
                        break;

                    }

                }

                if (!commit_inserted) {

                        ActivityDay activity_day = new ActivityDay (commit.DateTime);
                        activity_day.Add (commit);
                        activity_days.Add (activity_day);

                }

            }

            VBox layout_vertical = new VBox (false, 0);

            if (SparkleShare.Controller.Repositories.Find (
                    delegate (SparkleRepo r)
                        { return r.LocalPath.Equals (LocalPath) && r.HasUnsyncedChanges; }
                ) != null) {

                string title = _("This folder has unsynced changes");
                string text  = _("We will sync these once we’re connected again");

                SparkleInfobar infobar = new SparkleInfobar ("dialog-error", title, text);

                layout_vertical.PackStart (infobar, false, false, 0);

            } else {

                if (SparkleShare.Controller.Repositories.Find (
                    delegate (SparkleRepo r)
                        { return r.LocalPath.Equals (LocalPath) && r.HasUnsyncedChanges; }
                    ) != null) {

                        string title = _("Could not sync with the remote folder");
                        string text  = _("Is the you and the server online?");

                        SparkleInfobar infobar = new SparkleInfobar ("dialog-error", title, text);

                        layout_vertical.PackStart (infobar, false, false, 0);

                }

            }

            TreeView tree_view = new TreeView ();
            Gdk.Color background_color = tree_view.Style.Base (StateType.Normal);

            foreach (ActivityDay activity_day in activity_days) {

                EventBox box = new EventBox ();

                Label date_label = new Label ("") {
                    UseMarkup = true,
                    Xalign = 0,
                    Xpad = 9,
                    Ypad = 9
                };

                    DateTime today = DateTime.Now;
                    DateTime yesterday = DateTime.Now.AddDays (-1);

                    if (today.Day   == activity_day.DateTime.Day &&
                        today.Month == activity_day.DateTime.Month &&
                        today.Year  == activity_day.DateTime.Year) {

                        date_label.Markup = "<b>Today</b>";

                    } else if (yesterday.Day   == activity_day.DateTime.Day &&
                               yesterday.Month == activity_day.DateTime.Month &&
                               yesterday.Year  == activity_day.DateTime.Year) {

                        date_label.Markup = "<b>Yesterday</b>";

                    } else {

                        date_label.Markup = "<b>" + activity_day.DateTime.ToString ("ddd MMM d, yyyy") + "</b>";

                    }

                box.Add (date_label);
                layout_vertical.PackStart (box, false, false, 0);

                Gdk.Color color = Style.Foreground (StateType.Insensitive);
                string secondary_text_color = SparkleUIHelpers.GdkColorToHex (color);

                foreach (SparkleCommit change_set in activity_day) {

                    VBox log_entry     = new VBox (false, 0);
                    VBox deleted_files = new VBox (false, 0);
                    VBox edited_files  = new VBox (false, 0);
                    VBox added_files   = new VBox (false, 0);
                    VBox moved_files   = new VBox (false, 0);

                    foreach (string file_path in change_set.Edited) {

                        SparkleLink link = new SparkleLink (file_path,
                            SparkleHelpers.CombineMore (LocalPath, file_path));

                        link.ModifyBg (StateType.Normal, background_color);

                        edited_files.PackStart (link, false, false, 0);

                    }

                    foreach (string file_path in change_set.Added) {

                        SparkleLink link = new SparkleLink (file_path,
                            SparkleHelpers.CombineMore (LocalPath, file_path));

                        link.ModifyBg (StateType.Normal, background_color);

                        added_files.PackStart (link, false, false, 0);

                    }

                    foreach (string file_path in change_set.Deleted) {

                        SparkleLink link = new SparkleLink (file_path,
                            SparkleHelpers.CombineMore (LocalPath, file_path));

                        link.ModifyBg (StateType.Normal, background_color);

                        deleted_files.PackStart (link, false, false, 0);

                    }

                    for (int i = 0; i < change_set.MovedFrom.Count; i++) {

                        SparkleLink from_link = new SparkleLink (change_set.MovedFrom [i],
                            SparkleHelpers.CombineMore (LocalPath, change_set.MovedFrom [i]));

                        from_link.ModifyBg (StateType.Normal, background_color);

                        SparkleLink to_link = new SparkleLink (change_set.MovedTo [i],
                            SparkleHelpers.CombineMore (LocalPath, change_set.MovedTo [i]));

                        to_link.ModifyBg (StateType.Normal, background_color);

                        Label to_label = new Label ("<span fgcolor='" + secondary_text_color +"'>" +
                                                    "<small>to</small></span> ") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        HBox link_wrapper = new HBox (false, 0);
                        link_wrapper.PackStart (to_label, false, false, 0);
                        link_wrapper.PackStart (to_link, true, true, 0);

                        moved_files.PackStart (from_link, false, false, 0);
                        moved_files.PackStart (link_wrapper, false, false, 0);

                        if (change_set.MovedFrom.Count > 1)
                            moved_files.PackStart (new Label (""), false, false, 0);

                    }

                    HBox change_set_info_hbox = new HBox (false, 0);

                        Label change_set_info = new Label ("<b>" + change_set.UserName + "</b>") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        Label change_set_time = new Label ("<span fgcolor='" + secondary_text_color +"'><small>" +
                                                           change_set.DateTime.ToString ("H:mm") +
                                                           "</small></span>") {
                            Xalign = 1,
                            UseMarkup = true
                        };

                    change_set_info_hbox.PackStart (change_set_info, true, true, 0);
                    change_set_info_hbox.PackStart (change_set_time, false, false, 0);

                    log_entry.PackStart (change_set_info_hbox, false, false, 0);

                    if (edited_files.Children.Length > 0) {

                        Label edited_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
                                                        _("Edited") +
                                                        "</small></span>") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        log_entry.PackStart (edited_label, false, false, 0);
                        log_entry.PackStart (edited_files, false, false, 0);

                    }

                    if (added_files.Children.Length > 0) {

                        Label added_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
                                                        _("Added") +
                                                        "</small></span>") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        log_entry.PackStart (added_label, false, false, 0);
                        log_entry.PackStart (added_files, false, false, 0);

                    }

                    if (deleted_files.Children.Length > 0) {

                        Label deleted_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
                                                        _("Deleted") +
                                                        "</small></span>") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        log_entry.PackStart (deleted_label, false, false, 0);
                        log_entry.PackStart (deleted_files, false, false, 0);

                    }

                    if (moved_files.Children.Length > 0) {

                        Label moved_label = new Label ("\n<span fgcolor='" + secondary_text_color +"'><small>" +
                                                         _("Moved") +
                                                         "</small></span>") {
                            UseMarkup = true,
                            Xalign = 0
                        };

                        log_entry.PackStart (moved_label, false, false, 0);
                        log_entry.PackStart (moved_files, false, false, 0);

                    }

                    HBox hbox = new HBox (false, 0);

                    Image avatar = new Image (SparkleUIHelpers.GetAvatar (change_set.UserEmail, 32)) {
                        Yalign = 0
                    };

                    hbox.PackStart (avatar, false, false, 18);

                        VBox vbox = new VBox (false, 0);
                        vbox.PackStart (log_entry, false, false, 0);

                    hbox.PackStart (vbox, true, true, 0);
                    hbox.PackStart (new Label (""), false, false, 12);

                    layout_vertical.PackStart (hbox, false, false, 18);

                }

                layout_vertical.PackStart (new Label (""), false, false, 3);

            }

            ScrolledWindow = new ScrolledWindow ();

                EventBox wrapper = new EventBox ();
                wrapper.ModifyBg (StateType.Normal, background_color);
                wrapper.Add (layout_vertical);

            ScrolledWindow.AddWithViewport (wrapper);
            (ScrolledWindow.Child as Viewport).ShadowType = ShadowType.None;

            return ScrolledWindow;
        }
 protected void OnDeleteItem(ActivityDay activity)
 {
     _currentTimesheetForDay.Activities.Remove(activity);
     UpdateDayOfTimesheet(_currentTimesheetForDay);
 }