diff --git a/TODO.md b/TODO.md index 597753d7705a2..35e5c47bf2043 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,6 @@ List of TODO items for Panoramix ## Features -* **URL shortner** * **Dashboard URL filters:** `{dash_url}#fltin__fieldname__value1,value2` * **Default slice:** choose a default slice for the dataset instead of default endpoint * **refresh freq**: specifying the refresh frequency of a dashboard and specific slices within it, some randomization would be nice diff --git a/panoramix/migrations/versions/8e80a26a31db_.py b/panoramix/migrations/versions/8e80a26a31db_.py new file mode 100644 index 0000000000000..54edc58a80a36 --- /dev/null +++ b/panoramix/migrations/versions/8e80a26a31db_.py @@ -0,0 +1,32 @@ +"""empty message + +Revision ID: 8e80a26a31db +Revises: 2591d77e9831 +Create Date: 2016-01-13 20:24:45.256437 + +""" + +# revision identifiers, used by Alembic. +revision = '8e80a26a31db' +down_revision = '2591d77e9831' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.create_table('url', + sa.Column('created_on', sa.DateTime(), nullable=False), + sa.Column('changed_on', sa.DateTime(), nullable=False), + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('url', sa.Text(), nullable=True), + sa.Column('created_by_fk', sa.Integer(), nullable=True), + sa.Column('changed_by_fk', sa.Integer(), nullable=True), + sa.ForeignKeyConstraint(['changed_by_fk'], ['ab_user.id'], ), + sa.ForeignKeyConstraint(['created_by_fk'], ['ab_user.id'], ), + sa.PrimaryKeyConstraint('id') + ) + + +def downgrade(): + op.drop_table('url') diff --git a/panoramix/models.py b/panoramix/models.py index b12a2d7b0d067..3daf7b040fc79 100644 --- a/panoramix/models.py +++ b/panoramix/models.py @@ -49,6 +49,13 @@ def changed_on_(cls): return utils.datetime_f(cls.changed_on) +class Url(Model, AuditMixinNullable): + """Used for the short url feature""" + __tablename__ = 'url' + id = Column(Integer, primary_key=True) + url = Column(Text) + + class Slice(Model, AuditMixinNullable): """A slice is essentially a report or a view on data""" __tablename__ = 'slices' diff --git a/panoramix/static/panoramix.js b/panoramix/static/panoramix.js index 0659f0de59354..0c4cb2ad327d3 100644 --- a/panoramix/static/panoramix.js +++ b/panoramix/static/panoramix.js @@ -208,6 +208,24 @@ var px = (function() { $('legend').click(function () { toggle_fieldset($(this), true); }); + $('#shortner').click(function () { + $.ajax({ + type: "POST", + url: '/r/shortner/', + data: {'data': '/' + window.location.pathname + slice.querystring()}, + success: function(data) { + console.log(data); + data += '   '; + $('#shortner').popover({content: data, placement: 'left', html: true, trigger: 'manual'}); + $('#shortner').popover('show'); + $('#close_shortner').click(function(){ + $('#shortner').popover('destroy'); + }); + + }, + error: function() {alert("Error :(");}, + }); + }); $("#viz_type").change(function() {$("#query").submit();}); collapsed_fieldsets = get_collapsed_fieldsets(); for(var i=0; i < collapsed_fieldsets.length; i++){ diff --git a/panoramix/templates/panoramix/explore.html b/panoramix/templates/panoramix/explore.html index 11f701dccd8ea..5e979fc08e140 100644 --- a/panoramix/templates/panoramix/explore.html +++ b/panoramix/templates/panoramix/explore.html @@ -42,6 +42,9 @@ {{ form.get_field("viz_type")(class_="select2") }}
+ + + diff --git a/panoramix/views.py b/panoramix/views.py index 293f0282da65f..e28d7d8b1b8ef 100644 --- a/panoramix/views.py +++ b/panoramix/views.py @@ -310,6 +310,32 @@ def ping(): return "OK" +class R(BaseView): + + @utils.log_this + @expose("/") + def index(self, url_id): + url = db.session.query(models.Url).filter_by(id=url_id).first() + if url: + print(url.url) + return redirect('/' + url.url) + else: + flash("URL to nowhere...", "danger") + return redirect('/') + + @utils.log_this + @expose("/shortner/", methods=['POST', 'GET']) + def shortner(self): + url = request.form.get('data') + obj = models.Url(url=url) + db.session.add(obj) + db.session.commit() + return("{request.headers[Host]}/r/{obj.id}".format( + request=request, obj=obj)) + +appbuilder.add_view_no_menu(R) + + class Panoramix(BaseView): @has_access