예제 #1
0
        /// <summary>
        /// Creates a widget based on the parameters
        /// and links that widget to a dasboard.
        /// </summary>
        public Widget AddWidget(WidgetType widgetType, string title, int rowNbr, int colNbr, List <PropertyTag> proptags, DateTime?timestamp = null,
                                GraphType?graphType = null, int rowspan = 1, int colspan = 1, int dashboardId = -1, List <WidgetData> datas = null, List <Item> items = null)
        {
            InitRepo();
            Widget widget;

            //Checks if a userwidget or an itemWidget needs to be created
            if (dashboardId == -1)
            {
                widget = new ItemWidget();
            }
            else
            {
                widget = new UserWidget();
            }

            //Check if timestamp was given
            if (timestamp == null)
            {
                timestamp = DateTime.Now.AddMonths(-1);
            }

            widget.WidgetType   = widgetType;
            widget.Title        = title;
            widget.RowNumber    = rowNbr;
            widget.ColumnNumber = colNbr;
            widget.RowSpan      = rowspan;
            widget.ColumnSpan   = colspan;
            widget.Timestamp    = timestamp;
            widget.Items        = items ?? new List <Item>();
            if (graphType != 0)
            {
                widget.GraphType = graphType;
            }
            widget.PropertyTags = proptags;

            //Check for adding widgetData
            if (datas == null)
            {
                widget.WidgetDatas = new List <WidgetData>();
            }
            else
            {
                widget.WidgetDatas = datas;
            }

            //Update database
            if (dashboardId != -1)
            {
                Dashboard dasboardToAddWidget = widgetRepo.ReadDashboardWithWidgets(dashboardId);
                dasboardToAddWidget.Widgets.Add((UserWidget)widget);
            }
            widgetRepo.CreateWidget(widget);
            return(widget);
        }