Beispiel #1
0
def profile_dashboard(dashboard_id_str=None, dashboard_name=None):
    if not auth.access_profile():
        return redirect(url_for('bp_mqe.login', next='dashboard'))
    
    g.profile_page = 'dashboard'

    dbs = dashboards.OwnerDashboards(auth.logged_owner_id())
    if dashboard_id_str is None:
        active_db_id = dbs.dashboards[0].dashboard_id
    else:
        try:
            active_db_id = uuid.UUID(dashboard_id_str)
        except ValueError:
            abort(404)
        if active_db_id not in dbs.dashboard_by_id:
            abort(404)

    layout = Layout.select(auth.logged_owner_id(), active_db_id)

    if not reports.owner_has_reports(auth.logged_owner_id()):
        onboarding = True
    else:
        onboarding = False

    return render_template('profile_dashboard.html',
                   onboarding=onboarding,
                   dashboards=dbs,
                   active_db_id=active_db_id,
                   active_db_layout_id=layout.layout_id,
                   active_db_layout_dict=layout.layout_dict)
Beispiel #2
0
    def test_sscs_virtual_column(self):
        owner_id = uuid.uuid1()
        od = dashboards.OwnerDashboards(owner_id)
        dashboard_id = od.dashboards[0].dashboard_id

        r = Report.insert(owner_id, 'r')
        tile_config = {
            'tw_type': 'Single',
            'series_spec_list': [
                SeriesSpec(0, -1, dict(op='eq', args=['0'])),
            ],
            'tile_options': {}
        }
        tile_config['tile_options']['sscs'] = tile_config['series_spec_list'][
            0]

        tile = Tile.insert(owner_id, r.report_id, dashboard_id, tile_config)
        layouts.place_tile(tile)

        for inp in ['0', '1', '2\n3', '3\n4\n5\n']:
            res = r.process_input(inp)

        tile = Tile.select(
            dashboard_id,
            Layout.select(owner_id, dashboard_id).layout_dict.keys()[0])
        self.assertEqual(3, len(tile.series_specs()))
        return tile, r
Beispiel #3
0
    def delete(self):
        """Delete the report. The method detaches and deletes tiles that display the report.
        Report instances are NOT deleted by the method - the method
        :meth:`delete_multiple_instances` must be called before :meth:`delete` to achieve it.
        """
        from mqe import dashboards
        from mqe import layouts

        owner_dashboards = dashboards.OwnerDashboards(self.owner_id)
        for dashboard in owner_dashboards.dashboards:
            layout = layouts.Layout.select(self.owner_id,
                                           dashboard.dashboard_id)
            if not layout:
                continue
            tiles_to_detach = [
                tile for tile in layout.tile_dict
                if tile.report_id == self.report_id
            ]
            if tiles_to_detach:
                res = layouts.replace_tiles(
                    {tile: None
                     for tile in tiles_to_detach}, None)
                if not res:
                    return False

        c.dao.ReportDAO.delete(self.owner_id, self.report_id)

        return True
Beispiel #4
0
    def test_new_dashboard(self):
        data = []

        @signals.new_dashboard.connect
        def on_new_dashboard(c, **kwargs):
            data.append(kwargs['dashboard'])

        owner_id = uuid.uuid1()
        od = dashboards.OwnerDashboards(owner_id)
        self.assertEqual(data[0].dashboard_id, od.dashboards[0].dashboard_id)
        self.assertEqual(data[0].owner_id, od.dashboards[0].owner_id)

        od.insert_dashboard('dash2')
        self.assertEqual(2, len(data))

        od = dashboards.OwnerDashboards(owner_id)
        self.assertEqual(2, len(data))
Beispiel #5
0
def add_dashboard():
    name = request.get_json()['name'].strip()

    check_access(lambda: auth.access_profile())
    
    if not name:
        return error('Empty name')
    for invalid_char in ('/', '\\'):
        if invalid_char in name:
            return error('Invalid character "%s"' % invalid_char)

    dbs = dashboards.OwnerDashboards(auth.logged_owner_id())
    if name in {db.dashboard_name for db in dbs.dashboards}:
        return error('A dashboard with this name is already created')
    new_db = dbs.insert_dashboard(name, {})
    html = get_template_attribute('m.html', 'db_tab')(new_db, False, True)
    return success(result=dict(html=html))
Beispiel #6
0
def fetch_move_tile_data():
    dashboard_id = request.get_json()['dashboard_id']
    tile_id = request.get_json()['tile_id']

    check_access(lambda: auth.access_dashboard(dashboard_id))

    dbs = dashboards.OwnerDashboards(auth.logged_owner_id())
    options = [(serialize.mjson(db.dashboard_id), db.dashboard_name)
               for db in dbs.dashboards
               if db.dashboard_id != dashboard_id]
    tile = tiles.Tile.select(dashboard_id, tile_id)
    if not tile:
        return error('Invalid tile')
    result = dict(
        report_name=tile.report.report_name,
        has_options=bool(options),
        html_dashboard_select=get_template_attribute('m.html', 'select')('move-to-dashboard-select', options),
    )
    return success(result=result)
Beispiel #7
0
    def test_deleting_layout_by_report_row_after_deleting_dashboard(self):
        tile, report = self.test_sscs_virtual_column()
        report.process_input('3\n4\n5\n6')

        tile = Tile.select(
            tile.dashboard_id,
            Layout.select(tile.owner_id,
                          tile.dashboard_id).layout_dict.keys()[0])
        self.assertEqual(4, len(tile.series_specs()))

        od = dashboards.OwnerDashboards(tile.owner_id)
        for db in od.dashboards:
            db.delete()

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            tile.owner_id, tile.report_id, [], 'sscs', 100)
        self.assertTrue(rows)

        report.process_input('3\n4\n5\n6\n7\n8')

        rows = c.dao.LayoutDAO.select_layout_by_report_multi(
            tile.owner_id, tile.report_id, [], 'sscs', 100)
        self.assertFalse(rows)