Exemplo n.º 1
0
        private void Current_ConnectivityChanged(object sender, Plugin.Connectivity.Abstractions.ConnectivityChangedEventArgs e)
        {
            if (e.IsConnected)
            {
                Common.RefreshWorkList     = true;
                Common.RefreshProjectsList = true;

                ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();

                if (userMe != null)
                {
                    Common.UserGlobalCapability = userMe.UserGlobalCapability;


                    //userMe.NotificationNewCount = 131;
                    //var respo = UsersService.SaveUser(userMe);

                    string notifCount = string.Empty;
                    //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                    if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                    {
                        //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                        if (userMe.NotificationNewCount.Value > 99)
                        {
                            notifCount = "99+";
                        }
                        else
                        {
                            notifCount = userMe.NotificationNewCount.Value.ToString();
                        }
                    }
                    Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                    Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                    Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                }
                Common.WorkspaceCapability = WorkspaceService.GetWorkspaceCapability();
            }
            else
            {
                Common.RefreshWorkList     = false;
                Common.RefreshProjectsList = false;
            }
        }
Exemplo n.º 2
0
        public AddItemPage(Guid?parentId = null)
        {
            InitializeComponent();

            ParentId = parentId;
            //Check users permissions for adding Tasks, Projects, ToDos
            ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();

            //if (userMe != null && userMe.UserGlobalCapability != null && userMe.UserGlobalCapability.CanCreateProjects)
            if (Common.UserGlobalCapability != null && Common.UserGlobalCapability.CanCreateProjects && parentId == null)
            {
                slProject.IsVisible = true;
            }

            if (parentId == null)
            {
                slApproval.IsVisible = true;
                slTodos.IsVisible    = true;
            }
        }
        private async Task <bool> GetNotifications()
        {
            try
            {
                //Reset the badge counter
                SQLiteConnection connection             = Common.Instance.InitializeDatabase();
                ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();
                userMe.NotificationNewCount = 0;
                //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                Common.Instance.bottomNavigationViewModel.NumberNottificationItems = string.Empty;
                var saveresp = UsersService.SaveUser(userMe);


                var notifications = await NotificationsService.Get();

                if (notifications != null)
                {
                    myCollection = new ObservableCollection <Notification>();
                    foreach (var notif in notifications)
                    {
                        while (notif.Body.Contains("display:none"))
                        {
                            int from = notif.Body.Substring(0, notif.Body.IndexOf("display:none")).LastIndexOf("<");
                            int to   = notif.Body.IndexOf(">", notif.Body.IndexOf("display:none;\">") + 15) + 1;
                            notif.Body = notif.Body.Substring(0, from) + notif.Body.Substring(to);
                        }

                        var newNotif = new Notification()
                        {
                            Body = notif.Body,
                            CreatedDateTimeUTC = notif.CreatedDateTimeUTC,
                            IconImageUrl       = notif.IconImageUrl,
                            IconUrl            = notif.IconUrl,
                            ObjectEvent_Id     = notif.ObjectEvent_Id,
                            ObjectTypeString   = notif.ObjectTypeString,
                            IsBusy             = false,
                            Object_Id          = notif.Object_Id,
                            UserAvatarHTML     = notif.UserAvatarHTML,
                            UserCreated_Id     = notif.UserCreated_Id,
                            UserPhotoImageUrl  = notif.UserPhotoImageUrl
                        };

                        newNotif.AvatarColor    = "#1474BA";
                        newNotif.AvatarInitials = "PI";
                        if (string.IsNullOrEmpty(notif.UserPhotoImageUrl))
                        {
                            newNotif.ShowUserAvatar = true;
                            newNotif.ShowUserPhoto  = false;
                            if (!string.IsNullOrEmpty(notif.UserAvatarHTML))
                            {
                                string userHTML = notif.UserAvatarHTML;
                                //"<div class=\"user-avatar\" title=\"Gjoko Veljanoski\" style=\"background-color:#00bfff\">GV</div>"

                                string       myDiv = notif.UserAvatarHTML;
                                HtmlDocument doc   = new HtmlDocument();
                                doc.LoadHtml(myDiv);
                                HtmlNode node = doc.DocumentNode.SelectSingleNode("div");

                                newNotif.AvatarInitials = (node.ChildNodes[0]).OuterHtml;

                                foreach (HtmlAttribute attr in node.Attributes)
                                {
                                    if (attr.Name.ToLower() == "style")
                                    {
                                        string[] parts = attr.Value.Split('#');
                                        if (parts != null && parts.Length > 1)
                                        {
                                            newNotif.AvatarColor = "#" + parts[1];
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            newNotif.IconImageUrl   = Common.CurrentWorkspace.WorkspaceURL + notif.UserPhotoImageUrl;
                            newNotif.ShowUserAvatar = false;
                            newNotif.ShowUserPhoto  = true;
                        }
                        myCollection.Add(newNotif);
                    }
                }

                var template = new DataTemplate(typeof(TextCell));

                // We can set data bindings to our supplied objects.
                template.SetBinding(TextCell.TextProperty, "CreatedDateTimeUTC");
                template.SetBinding(TextCell.DetailProperty, "Body");

                //ItemsListView.ItemTemplate = template;

                if (myCollection == null || myCollection.Count == 0)
                {
                    lblNoNotif.IsVisible = true;
                }
                else
                {
                    lblNoNotif.IsVisible = false;
                }

                viewModel.Notifications = myCollection;
                BindingContext          = viewModel;
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
        public async Task <bool> GetUser()
        {
            try
            {
                ProjectInsight.Models.Users.User user = new ProjectInsight.Models.Users.User();
                if (UserID == null || UserID == Guid.Empty)
                {
                    await Task.Factory.StartNew(() =>
                    {
                        user = UsersService.GetMe();
                    });
                }
                else
                {
                    user = await UsersService.GetUser(UserID);
                }

                viewModel.Id    = user.Id.ToString();
                viewModel.Name  = user.Name;
                viewModel.Email = user.EmailAddress;

                viewModel.Company = user.Company != null ? user.Company.Name : String.Empty;
                if (viewModel.Company != String.Empty)
                {
                    viewModel.IsCompanyVisible = true;
                }


                viewModel.UserFirstLastName = user.FirstName + " " + user.LastName;
                viewModel.Address1          = user.Address1;
                viewModel.Address2          = user.Address2;

                var region   = user.Region != null && user.Region.Length > 0 ? ", " + user.Region : "";
                var postCode = user.PostCode != null && user.PostCode.Length > 0 ? ", " + user.PostCode : "";
                viewModel.CityRegionZip = user.City + region + postCode;
                viewModel.ZIP           = user.PostCode;
                viewModel.Phone         = user.Phone;
                viewModel.City          = user.City;
                viewModel.Region        = user.Region;
                viewModel.Country       = user.Country;

                if (!string.IsNullOrEmpty(user.PhotoUrl))
                {
                    viewModel.Photo           = Common.CurrentWorkspace.WorkspaceURL + user.PhotoUrl;
                    viewModel.IsPhotoVisible  = true;
                    viewModel.IsAvatarVisible = false;

                    //imgPhoto234.IsVisible = true;
                    wvAvatar.IsVisible = false;
                }
                else
                {
                    viewModel.IsPhotoVisible  = false;
                    viewModel.IsAvatarVisible = true;

                    //imgPhoto234.IsVisible = false;
                    wvAvatar.IsVisible = true;

                    if (user.AvatarHtml != String.Empty)
                    {
                        viewModel.AvatarHtml  = "<style>.user-avatar {font-family: 'Open Sans',segoe ui,verdana,helvetica;width: 125px!important;height: 125px!important;border-radius: 50%;line-height: 125px!important;font-size: 62px!important;color: #fff;text-align: center;margin: 0 !important;vertical-align: middle;overflow: hidden;cursor: pointer;display: inline-block;}</style>";
                        viewModel.AvatarHtml += user.AvatarHtml;
                    }
                }

                viewModel.Department = user.Department != null ? user.Department.Name : String.Empty;

                if (viewModel.Department != String.Empty)
                {
                    viewModel.IsDepartmentVisible = true;
                }
                if (viewModel.Address2 != null && viewModel.Address2.Length > 0)
                {
                    viewModel.IsAddress2Visible = true;
                }
                if (viewModel.Address1 != null && viewModel.Address1.Length > 0)
                {
                    viewModel.IsAddress1Visible = true;
                }
                if (viewModel.Country != null && viewModel.Country.Length > 0)
                {
                    viewModel.IsCountryVisible = true;
                }
                if (viewModel.Phone != null && viewModel.Phone.Length > 0)
                {
                    viewModel.IsPhoneVisible = true;
                }
                if (viewModel.City != null && viewModel.City.Length > 0)
                {
                    viewModel.IsCityVisible = true;
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public StartupMasterPage()
        {
            NavigationPage.SetBackButtonTitle(this, "");
            InitializeComponent();

            //MasterPage.ListView.ItemSelected += OnItemSelected;


            if (Common.PushNotificationAction != null)
            {
                //switch workspace
                if (Common.CurrentWorkspace == null || Common.CurrentWorkspace.DomainID != Common.PushNotificationAction.DomainId)
                {
                    var       workspaces = Common.Instance.GetWorkspaces();
                    Workspace ws;
                    ws = workspaces.FirstOrDefault(x => x.DomainID == Common.PushNotificationAction.DomainId);
                    if (ws != null)
                    {
                        foreach (Workspace wsp in workspaces.Where(x => x.isActive))
                        {
                            wsp.isActive = false;
                            Common.Instance._sqlconnection.Update(wsp);
                        }
                        ws.isActive = true;
                        Common.Instance._sqlconnection.Update(ws);
                        Common.CurrentWorkspace = ws;

                        if (!string.IsNullOrEmpty(ws.ApiToken) && ws.UserID != null)
                        {
                            //check if ApiToken is not expired
                            var handler = new JwtSecurityTokenHandler();
                            var tokenS  = handler.ReadToken(ws.ApiToken) as JwtSecurityToken;
                            var exp     = tokenS.Claims.First(claim => claim.Type == "exp").Value;

                            var expDate = tokenS.ValidTo;
                            if (expDate < DateTime.UtcNow.AddMinutes(1))
                            {
                                ws.ApiToken = null;
                                Common.Instance._sqlconnection.Update(ws);
                                Common.CurrentWorkspace = ws;
                                this.Detail             = new NavigationPage(new SignInUsingPhoneOrEmailPage());

                                return;
                            }

                            //if (AuthenticationService.PI_Client == null)
                            APIsInitialization.InitializeApis();

                            ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();
                            Common.UserGlobalCapability = userMe.UserGlobalCapability;
                            Common.WorkspaceCapability  = WorkspaceService.GetWorkspaceCapability();

                            string notifCount = string.Empty;
                            // Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                            if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                            {
                                //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                                if (userMe.NotificationNewCount.Value > 99)
                                {
                                    notifCount = "99+";
                                }
                                else
                                {
                                    notifCount = userMe.NotificationNewCount.Value.ToString();
                                }
                            }

                            Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                            Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                            Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                        }
                    }
                }

                //ProjectInsight.Items.Projects.Tasks.Task
                //ProjectInsight.Items.Projects.Project
                //ProjectInsight.Items.ApprovalRequests.ApprovalRequest
                //ProjectInsight.Items.Issues.Issue
                //ProjectInsight.Items.Files.File
                //ProjectInsight.Items.CustomItems.CustomItem
                //ProjectInsight.Items.Proposals.Proposal
                //ProjectInsight.Items.ToDos.ToDo
                //ProjectInsight.Items.Workflows.Workflow
                //ProjectInsight.Items.Domains.TimeAndBilling.TimeEntries.TimeSheet
                //ProjectInsightItems.Domains.TimeAndBilling.ExpenseEntries.ExpenseReport

                if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Projects.Tasks.Task")
                {
                    this.Detail = new NavigationPage(new TaskDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Projects.Project")
                {
                    this.Detail = new NavigationPage(new ProjectDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.ApprovalRequests.ApprovalRequest")
                {
                    this.Detail = new NavigationPage(new ApprovalRequestPage(Common.PushNotificationAction.ObjectId));
                }

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Issues.Issue")
                {
                    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Files.File")
                //    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.CustomItems.CustomItem")
                //    this.Detail = new NavigationPage(new IssueDetailsPage(Common.PushNotificationAction.ObjectId));

                else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.ToDos.ToDo")
                {
                    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                }

                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Workflows.Workflow")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsight.Items.Domains.TimeAndBilling.TimeEntries.TimeSheet")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));
                //else if (Common.PushNotificationAction.ObjectTypeString == "ProjectInsightItems.Domains.TimeAndBilling.ExpenseEntries.ExpenseReport")
                //    this.Detail = new NavigationPage(new ToDoDetailsPage(Common.PushNotificationAction.ObjectId));

                else
                {
                    this.Detail = new NavigationPage(new NotificationsPage());
                }

                Common.PushNotificationAction = null;
                return;
            }
        }
Exemplo n.º 6
0
        public App()
        {
            //Register Syncfusion license
            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MTMwMzUyQDMxMzcyZTMyMmUzMGJNN243dHFuWkNMRlVpaTY2U3BjVjVSSDh1Z2pMM0haVVdUSkFmOHh1ZnM9");

            InitializeComponent();


            //Check internet connection
            bool isConnected = CrossConnectivity.Current.IsConnected;

            CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;


            if (isConnected)
            {
                Common.RefreshWorkList     = true;
                Common.RefreshProjectsList = true;
            }
            //HockeyApp.MetricsManager.TrackEvent("Application initialization");

            SQLiteConnection connection = Common.Instance.InitializeDatabase();

            Common.Instance.bottomNavigationViewModel = new BottomNavigationViewModel();

            Common.Filter = new Filter();



            NavigationPage.SetBackButtonTitle(this, "");

            var workspaces = Common.Instance.GetWorkspaces();


            /// todo fixme
            if (workspaces == null || workspaces.Count() == 0)
            {
                if (Device.RuntimePlatform.ToLower() == "android")
                {
                    MainPage = new NavigationPage(new StartUp());
                }
                else
                {
                    MainPage = new NavigationPage(new SignInWorkSpace());
                }
                return;
            }

            Workspace ws;

            if (Common.PushNotificationAction != null)
            {
                ws = workspaces.FirstOrDefault(x => x.DomainID == Common.PushNotificationAction.DomainId);
                foreach (Workspace wsp in workspaces.Where(x => x.isActive))
                {
                    wsp.isActive = false;
                    Common.Instance._sqlconnection.Update(wsp);
                }
                if (ws != null)
                {
                    ws.isActive = true;
                    Common.Instance._sqlconnection.Update(ws);
                }
            }
            else
            {
                ws = workspaces.FirstOrDefault(x => x.isActive);
            }
            if (ws != null)
            {
                ws.isActive = true;
                Common.Instance._sqlconnection.Update(ws);

                Common.CurrentWorkspace = ws;

                //ws = workspaces.FirstOrDefault(x => x.isActive);

                if (!string.IsNullOrEmpty(ws.ApiToken) && ws.UserID != null)
                {
                    //check if ApiToken is not expired
                    var handler = new JwtSecurityTokenHandler();
                    var tokenS  = handler.ReadToken(ws.ApiToken) as JwtSecurityToken;
                    var exp     = tokenS.Claims.First(claim => claim.Type == "exp").Value;

                    var expDate = tokenS.ValidTo;
                    if (expDate < DateTime.UtcNow.AddMinutes(1))
                    {
                        ws.ApiToken = null;
                        Common.Instance._sqlconnection.Update(ws);
                        Common.CurrentWorkspace = ws;
                        MainPage = new NavigationPage(new SignInUsingPhoneOrEmailPage());

                        return;
                    }

                    //if (AuthenticationService.PI_Client == null)
                    APIsInitialization.InitializeApis();


                    if (isConnected)
                    {
                        ProjectInsight.Models.Users.User userMe = UsersService.GetSimpleMe();

                        if (userMe != null)
                        {
                            Common.UserGlobalCapability = userMe.UserGlobalCapability;


                            //userMe.NotificationNewCount = 131;
                            //var respo = UsersService.SaveUser(userMe);

                            string notifCount = string.Empty;
                            //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = false;
                            if (userMe.NotificationNewCount != null && userMe.NotificationNewCount.Value > 0)
                            {
                                //Common.Instance.bottomNavigationViewModel.IsNottificationContVisible = true;
                                if (userMe.NotificationNewCount.Value > 99)
                                {
                                    notifCount = "99+";
                                }
                                else
                                {
                                    notifCount = userMe.NotificationNewCount.Value.ToString();
                                }
                            }
                            Common.Instance.bottomNavigationViewModel.NumberNottificationItems = notifCount;
                            Common.Instance.bottomNavigationViewModel.NumberWorkListItems      = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType != ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                            Common.Instance.bottomNavigationViewModel.NumberProjectItems       = new ObservableCollection <MyWorkItem>(Common.Instance.GetUserWork().Where(x => x.ItemType == ItemType.Projects && x.WorkspaceId == Common.CurrentWorkspace.Id)).Count;
                        }
                        Common.WorkspaceCapability = WorkspaceService.GetWorkspaceCapability();
                    }

                    MainPage = new StartupMasterPage();

                    return;
                }
                else
                {
                    MainPage = new NavigationPage(new StartUp());
                    return;
                }
            }
            else
            {
                MainPage = new NavigationPage(new ChooseWorkspace());
                return;
            }
        }