Persist normal/compact views across sessions. Closes #76.
parent
357dc6f4b1
commit
71aaed6f8f
|
@ -0,0 +1,83 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'UserProfile.list_view'
|
||||
db.add_column(u'accounts_userprofile', 'list_view',
|
||||
self.gf('django.db.models.fields.CharField')(default='N', max_length=1),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'UserProfile.list_view'
|
||||
db.delete_column(u'accounts_userprofile', 'list_view')
|
||||
|
||||
|
||||
models = {
|
||||
u'accounts.userprofile': {
|
||||
'Meta': {'object_name': 'UserProfile'},
|
||||
'blog_domain': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'blog_theme': ('django.db.models.fields.CharField', [], {'default': "'D'", 'max_length': '1'}),
|
||||
'blog_title': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'default_editor': ('django.db.models.fields.CharField', [], {'default': "'C'", 'max_length': '250'}),
|
||||
'disqus_shortname': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'editor_theme': ('django.db.models.fields.CharField', [], {'default': "'default'", 'max_length': '250'}),
|
||||
'gauges_site_id': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'gittip_username': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'google_ad_client': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'google_ad_height': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'google_ad_slot': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'google_ad_width': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'google_analytics_tracking_id': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
|
||||
'has_gravatar': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_pro': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'list_view': ('django.db.models.fields.CharField', [], {'default': "'N'", 'max_length': '1'}),
|
||||
'stripe_id': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
|
||||
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'unique': 'True'})
|
||||
},
|
||||
u'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
u'auth.permission': {
|
||||
'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
u'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
u'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['accounts']
|
|
@ -4,6 +4,11 @@ from snipts.models import Snipt
|
|||
|
||||
class UserProfile(models.Model):
|
||||
|
||||
LIST_VIEW_CHOICES = (
|
||||
('N', 'Normal'),
|
||||
('C', 'Compact'),
|
||||
)
|
||||
|
||||
EDITOR_CHOICES = (
|
||||
('C', 'CodeMirror'),
|
||||
('T', 'Textarea'),
|
||||
|
@ -39,6 +44,7 @@ class UserProfile(models.Model):
|
|||
is_pro = models.BooleanField(default=False)
|
||||
stripe_id = models.CharField(max_length=100, null=True, blank=True)
|
||||
has_gravatar = models.BooleanField(default=False)
|
||||
list_view = models.CharField(max_length=1, null=False, blank=False,default='N', choices=LIST_VIEW_CHOICES)
|
||||
|
||||
# Blog
|
||||
blog_title = models.CharField(max_length=250, null=True, blank=True)
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,7 @@
|
|||
(function() {
|
||||
|
||||
'use strict';
|
||||
|
||||
if (typeof angular !== 'undefined') {
|
||||
|
||||
var root = this;
|
||||
|
@ -8,8 +10,23 @@
|
|||
var app = root.app;
|
||||
|
||||
// Controllers.
|
||||
controllers.SniptListController = function($scope) {
|
||||
$scope.section = 'Billing';
|
||||
controllers.SniptListController = function($scope, AccountStorage) {
|
||||
|
||||
$scope.$root.account = {
|
||||
list_view: 'N'
|
||||
};
|
||||
|
||||
AccountStorage.getAccount().then(function(response) {
|
||||
$scope.$root.account = response.data;
|
||||
});
|
||||
|
||||
$scope.$root.$watch('account.list_view', function(oldView, newView) {
|
||||
if (oldView !== newView) {
|
||||
AccountStorage.saveAccount($scope.$root.account, ['list_view']).then(function(response) {
|
||||
$scope.$root.account = response.data;
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Assign the controllers.
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
</li>
|
||||
{% if has_snipts %}
|
||||
<li class="compact">
|
||||
<a ng-click="compactView=true" href>Compact</a>
|
||||
<a ng-click="$root.account.list_view = 'C'" href>Compact</a>
|
||||
</li>
|
||||
<li class="normal">
|
||||
<a ng-click="compactView=false" href>Normal</a>
|
||||
<a ng-click="$root.account.list_view = 'N'" href>Normal</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
</li>
|
||||
{% if snipts %}
|
||||
<li class="compact">
|
||||
<a ng-click="compactView=true" href>Compact</a>
|
||||
<a ng-click="$root.account.list_view = 'C'" href>Compact</a>
|
||||
</li>
|
||||
<li class="normal">
|
||||
<a ng-click="compactView=false" href>Normal</a>
|
||||
<a ng-click="$root.account.list_view = 'N'" href>Normal</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -12,7 +12,10 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="snipts" id="snipts" ng-controller="SniptListController">
|
||||
<section class="snipts" id="snipts" ng-controller="SniptListController"
|
||||
{% if request.user.profile.list_view == 'C' %}
|
||||
ng-cloak ng-show="$root.account.id"
|
||||
{% endif %}>
|
||||
{% autopaginate snipts 20 %}
|
||||
{% for snipt in snipts %}
|
||||
{% include "snipts/snipt-list.html" %}
|
||||
|
|
|
@ -22,18 +22,18 @@
|
|||
favorited" data-favorite-id="{{ is_favorited }}"
|
||||
{% else %}
|
||||
"
|
||||
{% endif %} ng-class="{compact: compactView}">
|
||||
{% endif %} ng-class="{compact: account.list_view == 'C'}">
|
||||
<div class="number">#{{ snipt.pk }}</div>
|
||||
<div class="group">
|
||||
<div class="container {% if snipt.description %}with-description{% endif %}">
|
||||
<header>
|
||||
{% block lexer %}
|
||||
<h2 ng-show="!compactView">{{ snipt.lexer_name }}</h2>
|
||||
<h2 ng-show="!account || account.list_view == 'N'">{{ snipt.lexer_name }}</h2>
|
||||
{% endblock %}
|
||||
<h1><a href="{{ snipt.get_absolute_url }}">{% if snipt.title %}{{ snipt.title }}{% else %}Untitled{% endif %}</a></h1>
|
||||
{% block extra-snipt-header %}{% endblock %}
|
||||
</header>
|
||||
<section ng-show="!compactView" class="code {% if request.GET.style %}{{ request.GET.style }}{% else %}autumn{% endif %}">
|
||||
<section ng-show="!account || account.list_view == 'N'" class="code {% if request.GET.style %}{{ request.GET.style }}{% else %}autumn{% endif %}">
|
||||
{% if snipt.lexer == 'markdown' %}
|
||||
<div class="markdown">
|
||||
{% if snipt.line_count > 300 and not detail %}
|
||||
|
@ -99,7 +99,7 @@
|
|||
<div class="ruler bottom-x"></div>
|
||||
</div>
|
||||
{% block aside %}
|
||||
<aside ng-show="!compactView">
|
||||
<aside ng-show="!account || account.list_view == 'N'">
|
||||
<ul class="options">
|
||||
{% if snipt.user == request.user %}
|
||||
<li>
|
||||
|
@ -154,7 +154,7 @@
|
|||
</aside>
|
||||
{% endblock %}
|
||||
</div>
|
||||
<footer ng-show="!compactView">
|
||||
<footer ng-show="!account || account.list_view == 'N'">
|
||||
<ul class="attrs">
|
||||
{% block author %}
|
||||
<li class="author">
|
||||
|
|
Loading…
Reference in New Issue