public List <Product> GetProducts(User user)
        {
            if (user.ProductsRoles == null || !user.ProductsRoles.Any())
            {
                return(null);
            }

            return(_productManager.Products.Where(p =>
                                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList());
        }
        public List <Product> GetProducts(User user)
        {
            if (user.IsAdmin)
            {
                return(Products);
            }

            if (user.ProductsRoles == null || user.ProductsRoles.Count == 0)
            {
                return(null);
            }

            return(Products.Where(p =>
                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList());
        }
Example #3
0
        public List <User> GetAllViewers(string productKey)
        {
            if (_users == null || _users.Count == 0)
            {
                return(null);
            }

            List <User> result = new List <User>();

            foreach (var user in _users)
            {
                if (ProductRoleHelper.IsViewer(productKey, user.ProductsRoles))
                {
                    result.Add(user);
                }
            }

            return(result);
        }
Example #4
0
        public List <User> GetManagers(string productKey)
        {
            if (_users == null || !_users.Any())
            {
                return(null);
            }

            List <User> result = new List <User>();

            foreach (var user in _users)
            {
                if (ProductRoleHelper.IsManager(productKey, user.ProductsRoles))
                {
                    result.Add(user);
                }
            }

            return(result);
        }
        public List <SensorData> GetSensorsTree(User user)
        {
            if (!_queueManager.IsUserRegistered(user))
            {
                _queueManager.AddUserSession(user);
            }

            List <SensorData> result = new List <SensorData>();
            var productsList         = _productManager.Products;

            //Show available products only
            if (!UserRoleHelper.IsAllProductsTreeAllowed(user))
            {
                productsList = productsList.Where(p =>
                                                  ProductRoleHelper.IsAvailable(p.Key, user.ProductsRoles)).ToList();
            }

            //foreach (var product in productsList)
            //{
            //result.AddRange();
            //var sensorsList = _productManager.GetProductSensors(product.Name);
            //foreach (var sensor in sensorsList)
            //{
            //    var cachedVal = _valuesCache.GetValue(product.Name, sensor.Path);
            //    if (cachedVal != null)
            //    {
            //        result.Add(cachedVal);
            //        continue;
            //    }
            //    var lastVal = _database.GetLastSensorValue(product.Name, sensor.Path);
            //    if (lastVal != null)
            //    {
            //        result.Add(_converter.Convert(lastVal, product.Name));
            //    }
            //}
            //}
            result.AddRange(_valuesCache.GetValues(productsList.Select(p => p.Name).ToList()));

            return(result);
        }
 public static bool IsSensorAvailable(this User user, string key)
 {
     return(ProductRoleHelper.IsAvailable(key, user.ProductsRoles));
 }
        public static string CreateTable(User user, List <ProductViewModel> products)
        {
            StringBuilder result = new StringBuilder();

            //header template
            result.Append("<div style='margin: 10px'>" +
                          "<div class='row justify-content-start'><div class='col-2'>" +
                          "<h5 style='margin: 10px 20px 10px;'>Products</h5></div></div></div>");


            result.Append("<div class='col-xxl'>");
            //table template
            result.Append("<table class='table table-striped'><thead><tr>" +
                          "<th scope='col'>#</th>" +
                          "<th scope='col'>Name</th>" +
                          "<th scope='col'>Key</th>" +
                          "<th scope='col'>Creation Date</th>" +
                          "<th scope='col'>Manager</th>");

            if (UserRoleHelper.IsProductCRUDAllowed(user) ||
                ProductRoleHelper.IsProductActionAllowed(user.ProductsRoles))
            {
                result.Append("<th scope='col'>Action</th></tr>");
            }

            result.Append("</thead><tbody>");

            //create
            if (UserRoleHelper.IsProductCRUDAllowed(user))
            {
                result.Append("<tr><th>0</th>" +
                              "<th><input id='createName' type='text' class='form-control'/>" +
                              "<span style='display: none;' id='new_product_name_span'></th>" +
                              "<th>---</th>" +
                              $"<th>---</th>" +
                              $"<th>---</th>" +
                              "<th><button id='createButton' style='margin-left: 5px' type='button' class='btn btn-secondary' title='create'>" +
                              $"<i class='fas fa-plus'></i></button></th></tr>");
            }

            if (products == null || products.Count == 0)
            {
                return(result.ToString());
            }

            int index = 1;

            foreach (var product in products)
            {
                result.Append($"<tr><th scope='row'>{index}</th>" +
                              $"<td>{product.Name}</td>" +
                              $"<td id='key_{product.Key}' value='{product.Key}'>{product.Key} " +
                              $"<button id='copy_{product.Key}' data-clipboard-text='{product.Key}' title='copy key' type='button' class='btn btn-secondary'>" +
                              $"<i class='far fa-copy'></i></button>" +
                              $"<input style='display: none' type='text' id='inputName_{product.Key}' value='{product.Name}'/></td>" +
                              $"<td>{product.CreationDate}</td>" +
                              $"<td>{product.ManagerName}</td>");


                if (UserRoleHelper.IsProductCRUDAllowed(user) ||
                    ProductRoleHelper.IsManager(product.Key, user.ProductsRoles))
                {
                    result.Append($"<td><button style='margin-left: 5px' id='change_{product.Key}' " +
                                  $"type='button' class='btn btn-secondary' title='edit'>" +
                                  "<i class='fas fa-edit'></i></button>");
                }

                if (UserRoleHelper.IsProductCRUDAllowed(user))
                {
                    result.Append($"<button id='delete_{product.Key}' style='margin-left: 5px' " +
                                  $"type='button' class='btn btn-secondary' title='delete'>" +
                                  $"<i class='fas fa-trash-alt'></i></button>");
                }

                result.Append("</tr>");
                index++;
            }

            result.Append("</tbody></table></div></div>");

            return(result.ToString());
        }