示例#1
1
        public async Task <Dashboard> GetDashboardForAsync(TuxboardConfig config, string userId)
        {
            Dashboard dashboard;

            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();

                dashboard = CreateDashboardFrom(template, userId);

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

            return(await _context.GetDashboardForAsync(config, userId));
        }
示例#2
0
        public static Dashboard GetDashboardFor(this ITuxDbContext context, TuxboardConfig 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);
        }
示例#3
0
        public static async Task <Dashboard> GetDashboardForAsync(this ITuxDbContext context,
                                                                  TuxboardConfig config, string userId)
        {
            var layoutTypes = context.LayoutType.ToList();

            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);
        }
示例#4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();

            var appConfig = new TuxboardConfig();
            Configuration
                .GetSection(nameof(TuxboardConfig))
                .Bind(appConfig);

            services.AddDbContext<TuxDbContext>(options =>
                options.UseSqlServer(appConfig.ConnectionString,
                    b => b.MigrationsAssembly("UserDashboard")));

            services.AddDbContext<ApplicationDbContext>(options =>
                options.UseSqlServer(
                    Configuration.GetConnectionString("DefaultConnection")));

            services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
                .AddEntityFrameworkStores<ApplicationDbContext>();
            
            services.AddRazorPages();

            services.Configure<RazorViewEngineOptions>(o =>
            {
                o.ViewLocationExpanders.Add(
                    new TuxboardViewLocationExpander(
                        appConfig.WidgetFolder,
                        appConfig.ViewFolder,
                        appConfig.ComponentFolder + RazorViewEngine.ViewExtension));
            });

            services.AddTransient<IDashboardService, DashboardService>();
            services.AddScoped<ITuxDbContext, TuxDbContext>();
        }
 public TuxboardController(ILogger <TuxboardController> logger,
                           IDashboardService service,
                           IOptions <TuxboardConfig> config)
 {
     _logger  = logger;
     _service = service;
     _config  = config.Value;
 }
示例#6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var appConfig = new TuxboardConfig();

            Configuration
            .GetSection(nameof(TuxboardConfig))
            .Bind(appConfig);

            services.AddDbContext <TuxDbContext>(options =>
                                                 options.UseSqlServer(appConfig.ConnectionString));

            services.AddRazorPages();

            services.AddTransient <IDashboardService, DashboardService>();
            services.AddTransient <ITuxDbContext, TuxDbContext>();
        }
示例#7
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions();

            var appConfig = new TuxboardConfig();

            Configuration
            .GetSection(nameof(TuxboardConfig))
            .Bind(appConfig);

            services.AddDbContext <TuxDbContext>(options => options.UseSqlServer(appConfig.ConnectionString));

            services.AddControllersWithViews();

            services.Configure <RazorViewEngineOptions>(o =>
            {
                o.ViewLocationExpanders.Add(new WidgetViewLocationExpander());
            });
        }
示例#8
0
 public DashboardService(ITuxDbContext context, IConfiguration config)
 {
     _context = context;
     _config  = config.Get <TuxboardConfig>();
 }