예제 #1
0
        public static Dashboard GetDashboardFor(this ITuxDbContext context, ITuxboardConfig config, string userId)
        {
            var layoutTypes = context.LayoutType.ToList();

            var dashboard = context.Dashboard
                            .Include(db => db.Tabs)
                            .ThenInclude(tab => tab.Layouts)
                            .ThenInclude(layout => layout.LayoutRows)
                            .AsNoTracking()
                            .FirstOrDefault(t => t.UserId == userId);

            if (dashboard == null)
            {
                return(null);
            }

            // Assign the LayoutTypes to each row; get the settings for the WidgetPlacements.
            foreach (var tab in dashboard.Tabs)
            {
                foreach (var row in tab.GetLayouts().SelectMany(layout => layout.LayoutRows))
                {
                    row.LayoutType       = layoutTypes.FirstOrDefault(e => e.LayoutTypeId == row.LayoutTypeId);
                    row.WidgetPlacements = context.GetPlacementsByLayoutRow(row.LayoutRowId);
                }
            }

            dashboard.Settings = config;

            return(dashboard);
        }
예제 #2
0
        public static async Task <Dashboard> GetDashboardForAsync(this ITuxDbContext context,
                                                                  ITuxboardConfig config, string userId)
        {
            var layoutTypes = await context.LayoutType.ToListAsync();

            var dashboard = await context.Dashboard
                            .Include(db => db.Tabs)
                            .ThenInclude(tab => tab.Layouts)
                            .ThenInclude(layout => layout.LayoutRows)
                            .AsNoTracking()
                            .FirstOrDefaultAsync(e => e.UserId == userId);

            if (dashboard == null)
            {
                return(null);
            }

            foreach (var tab in dashboard.Tabs)
            {
                foreach (var row in tab.GetLayouts().SelectMany(layout => layout.LayoutRows))
                {
                    row.LayoutType       = layoutTypes.FirstOrDefault(e => e.LayoutTypeId == row.LayoutTypeId);
                    row.WidgetPlacements = await context.GetPlacementsByLayoutRowAsync(row.LayoutRowId);
                }
            }

            dashboard.Settings = config;

            return(dashboard);
        }
예제 #3
0
 public TuxboardController(ILogger <TuxboardController> logger,
                           IDashboardService service,
                           IOptions <TuxboardConfig> config)
 {
     _logger  = logger;
     _service = service;
     _config  = config.Value;
 }
예제 #4
0
        public async Task <Dashboard> GetDashboardForAsync(ITuxboardConfig config, string userId)
        {
            if (!await _context.DashboardExistsForAsync(userId))
            {
                // Pass in a planid (int) to pull back specific dashboards.
                // If nothing passed, it'll grab the first Dashboard Template.
                var template = await _context.GetDashboardTemplateForAsync();

                await CreateDashboardFromAsync(template, userId);

                await _context.SaveChangesAsync(new CancellationToken());
            }

            return(await _context.GetDashboardForAsync(config, userId));
        }
예제 #5
0
        public Dashboard GetDashboardFor(ITuxboardConfig config, string userId)
        {
            if (!_context.DashboardExistsFor(userId))
            {
                // Pass in a planid (int) to pull back specific dashboards.
                // If nothing passed, it'll grab the first Dashboard Template.
                var template = _context.GetDashboardTemplateFor();

                CreateDashboardFrom(template, userId);

                _context.SaveChanges();
            }

            var dashboard = _context.GetDashboardFor(config, userId);

            dashboard.Settings = config;

            return(dashboard);
        }
예제 #6
0
 public Dashboard GetDashboard(ITuxboardConfig config)
 {
     return(_context.GetDashboard(config));
 }