Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A welcome page #198

Merged
merged 2 commits into from
Mar 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dashed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class MyIndexView(IndexView):
@expose('/')
def index(self):
return redirect('/dashed/featured')
return redirect('/dashed/welcome')

appbuilder = AppBuilder(
app, db.session,
Expand Down
2 changes: 1 addition & 1 deletion dashed/assets/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
}],
"max-depth": [2, 5],
"max-len": [0, 80, 4],
"max-nested-callbacks": [1, 2],
"max-nested-callbacks": [1, 3],
"max-params": [1, 4],
"new-parens": [2],
"newline-after-var": [0],
Expand Down
19 changes: 0 additions & 19 deletions dashed/assets/javascripts/featured.js

This file was deleted.

48 changes: 48 additions & 0 deletions dashed/assets/javascripts/welcome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var $ = window.$ = require('jquery');
var jQuery = window.jQuery = $;

require('../stylesheets/dashed.css');
require('../stylesheets/welcome.css');
require('bootstrap');
require('datatables');
require('../node_modules/cal-heatmap/cal-heatmap.css');

var CalHeatMap = require('cal-heatmap');

function modelViewTable(selector, modelEndpoint, ordering) {
// Builds a dataTable from a flask appbuilder api endpoint
$.getJSON(modelEndpoint + '/api/read', function (data) {
var tableData = jQuery.map(data.result, function (el, i) {
var row = $.map(data.list_columns, function (col, i) {
return el[col];
});
return [row];
});
var cols = jQuery.map(data.list_columns, function (col, i) {
return { sTitle: data.label_columns[col] };
});
$(selector).DataTable({
aaData: tableData,
aoColumns: cols,
bPaginate: false,
order: ordering,
searching: false
});
$('[data-toggle="tooltip"]').tooltip({ container: 'body' });
});
}

$(document).ready(function () {
var cal = new CalHeatMap();
cal.init({
start: new Date().setFullYear(new Date().getFullYear() - 1),
range: 13,
data: '/dashed/activity_per_day',
domain: "month",
subDomain: "day",
itemName: "action",
tooltip: true
});
modelViewTable('#dash_table', '/dashboardmodelviewasync');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just something to note: every time you give a DOM element an id, it creates a GLOBAL javascript variable with that id name. there are tons of instances of using #my_id selectors in the code base so it's probably not worth changing at this point, but going forward it is better to use classes than ids for DOM elements and selections.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I didn't know that... will avoid id moving forward, a unique class works just as well

modelViewTable('#slice_table', '/sliceasync');
});
1 change: 1 addition & 0 deletions dashed/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"bootstrap-datepicker": "^1.6.0",
"bootstrap-toggle": "^2.2.1",
"brace": "^0.7.0",
"cal-heatmap": "3.5.4",
"css-loader": "^0.23.1",
"d3": "^3.5.14",
"d3-cloud": "^1.2.1",
Expand Down
8 changes: 8 additions & 0 deletions dashed/assets/stylesheets/dashed.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ body {
font-size: 100%;
}

.no-wrap {
white-space: nowrap;
}

input.form-control {
background-color: white;
}
Expand Down Expand Up @@ -68,6 +72,10 @@ form div {
}
.navbar-brand a {
color: white;
text-decoration: none;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank god! that was annoying me 👍

}
.navbar-brand a:hover {
color: white;
}

.header span {
Expand Down
21 changes: 21 additions & 0 deletions dashed/assets/stylesheets/welcome.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.welcome .widget{
border-radius: 0;
border: 1px solid #ccc;
box-shadow: 2px 1px 5px -2px #aaa;
background-color: #fff;
}

.welcome .widget .header {
background-color: #f1f1f1;
text-align: center;
}

.welcome .widget>div {
padding: 3px;
overflow: auto;
max-height: 500px;
}

.table i {
padding-top: 6px;
}
2 changes: 1 addition & 1 deletion dashed/assets/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var config = {
'css-theme': APP_DIR + '/javascripts/css-theme.js',
dashboard: APP_DIR + '/javascripts/dashboard.js',
explore: APP_DIR + '/javascripts/explore.js',
featured: APP_DIR + '/javascripts/featured.js',
welcome: APP_DIR + '/javascripts/welcome.js',
sql: APP_DIR + '/javascripts/sql.js',
standalone: APP_DIR + '/javascripts/standalone.js'
},
Expand Down
22 changes: 22 additions & 0 deletions dashed/migrations/versions/1d2ddd543133_log_dt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""log dt

Revision ID: 1d2ddd543133
Revises: d2424a248d63
Create Date: 2016-03-25 14:35:44.642576

"""

# revision identifiers, used by Alembic.
revision = '1d2ddd543133'
down_revision = 'd2424a248d63'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.add_column('logs', sa.Column('dt', sa.Date(), nullable=True))


def downgrade():
op.drop_column('logs', 'dt')
29 changes: 27 additions & 2 deletions dashed/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from copy import deepcopy, copy
from collections import namedtuple
from datetime import timedelta, datetime
from datetime import timedelta, datetime, date
import functools
import json
import logging
Expand All @@ -15,12 +15,13 @@
from flask.ext.appbuilder import Model
from flask.ext.appbuilder.models.mixins import AuditMixin
import pandas as pd
import humanize
from pydruid import client
from pydruid.utils.filters import Dimension, Filter

import sqlalchemy as sqla
from sqlalchemy import (
Column, Integer, String, ForeignKey, Text, Boolean, DateTime,
Column, Integer, String, ForeignKey, Text, Boolean, DateTime, Date,
Table, create_engine, MetaData, desc, select, and_, func)
from sqlalchemy.engine import reflection
from sqlalchemy.orm import relationship
Expand Down Expand Up @@ -68,6 +69,22 @@ def created_by_(self):
def changed_by_(self):
return '{}'.format(self.changed_by or '')

@property
def modified(self):
s = humanize.naturaltime(datetime.now() - self.changed_on)
return '<span class="no-wrap">{}</nobr>'.format(s)

@property
def icons(self):
return """
<a
href="{self.datasource_edit_url}"
data-toggle="tooltip"
title="{self.datasource}">
<i class="fa fa-database"></i>
</a>
""".format(**locals())


class Url(Model, AuditMixinNullable):

Expand Down Expand Up @@ -123,6 +140,13 @@ def datasource_link(self):
elif self.druid_datasource:
return self.druid_datasource.link

@property
def datasource_edit_url(self):
if self.table:
return self.table.url
elif self.druid_datasource:
return self.druid_datasource.url

@property
@utils.memoized
def viz(self):
Expand Down Expand Up @@ -1057,6 +1081,7 @@ class Log(Model):
json = Column(Text)
user = relationship('User', backref='logs', foreign_keys=[user_id])
dttm = Column(DateTime, default=func.now())
dt = Column(Date, default=date.today())

@classmethod
def log_this(cls, f):
Expand Down
42 changes: 0 additions & 42 deletions dashed/templates/dashed/featured.html

This file was deleted.

39 changes: 39 additions & 0 deletions dashed/templates/dashed/welcome.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "dashed/basic.html" %}

{% block head_js %}
{{ super() }}
<script src="/static/assets/javascripts/dist/welcome.entry.js"></script>
{% endblock %}

{% block title %}Welcome!{% endblock %}

{% block body %}
<div class="container welcome">
<div class="header">
<h3><i class='fa fa-star'></i> Welcome!</h3>
</div>
<hr/>
<div id="cal-heatmap"></div>
<hr/>
<div class="row">
<div class="col-md-6">
<div class="widget">
<div class="header"><h4><i class="fa fa-dashboard"></i> Dashboards</h4></div>
<div>
<table id="dash_table" class="table"></table>
</div>
</div>
</div>
<div class="col-md-6">
<div class="widget">
<div class="header"><h4><i class="fa fa-bar-chart"></i> Slices</h4></div>
<div>
<table id="slice_table" class="table"></table>
</div>
</div>
</div>
</div>
</div>
<hr/>
{% endblock %}

4 changes: 2 additions & 2 deletions dashed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,15 @@ def init(dashed):
for perm in perms:
if perm.permission.name == 'datasource_access':
continue
if perm.view_menu.name not in (
if perm.view_menu and perm.view_menu.name not in (
'UserDBModelView', 'RoleModelView', 'ResetPasswordView',
'Security'):
sm.add_permission_role(alpha, perm)
sm.add_permission_role(admin, perm)
gamma = sm.add_role("Gamma")
for perm in perms:
if(
perm.view_menu.name not in (
perm.view_menu and perm.view_menu.name not in (
'ResetPasswordView',
'RoleModelView',
'UserDBModelView',
Expand Down
Loading