From c77d0afc18ffb8a823aa8987065e29120bea3778 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sun, 14 Jul 2013 12:47:40 +0000 Subject: [PATCH] add calculated values to edit clips(hue,saturation,lightness,volume) add api to sort clips --- pandora/edit/migrations/0003_sort.py | 236 +++++++++++++++++++++++++++ pandora/edit/models.py | 29 +++- pandora/edit/views.py | 44 ++++- static/js/pandora/editPanel.js | 31 +++- 4 files changed, 330 insertions(+), 10 deletions(-) create mode 100644 pandora/edit/migrations/0003_sort.py diff --git a/pandora/edit/migrations/0003_sort.py b/pandora/edit/migrations/0003_sort.py new file mode 100644 index 00000000..301139ac --- /dev/null +++ b/pandora/edit/migrations/0003_sort.py @@ -0,0 +1,236 @@ +# -*- 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 'Clip.duration' + db.add_column('edit_clip', 'duration', + self.gf('django.db.models.fields.FloatField')(default=0), + keep_default=False) + + # Adding field 'Clip.hue' + db.add_column('edit_clip', 'hue', + self.gf('django.db.models.fields.FloatField')(default=0), + keep_default=False) + + # Adding field 'Clip.saturation' + db.add_column('edit_clip', 'saturation', + self.gf('django.db.models.fields.FloatField')(default=0), + keep_default=False) + + # Adding field 'Clip.lightness' + db.add_column('edit_clip', 'lightness', + self.gf('django.db.models.fields.FloatField')(default=0), + keep_default=False) + + # Adding field 'Clip.volume' + db.add_column('edit_clip', 'volume', + self.gf('django.db.models.fields.FloatField')(default=0), + keep_default=False) + + + def backwards(self, orm): + # Deleting field 'Clip.duration' + db.delete_column('edit_clip', 'duration') + + # Deleting field 'Clip.hue' + db.delete_column('edit_clip', 'hue') + + # Deleting field 'Clip.saturation' + db.delete_column('edit_clip', 'saturation') + + # Deleting field 'Clip.lightness' + db.delete_column('edit_clip', 'lightness') + + # Deleting field 'Clip.volume' + db.delete_column('edit_clip', 'volume') + + + models = { + 'annotation.annotation': { + 'Meta': {'object_name': 'Annotation'}, + 'clip': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'annotations'", 'null': 'True', 'to': "orm['clip.Clip']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'end': ('django.db.models.fields.FloatField', [], {'default': '-1', 'db_index': 'True'}), + 'findvalue': ('django.db.models.fields.TextField', [], {'null': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'item': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'annotations'", 'to': "orm['item.Item']"}), + 'layer': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'public_id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'unique': 'True', 'null': 'True'}), + 'sortvalue': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '1000', 'null': 'True', 'blank': 'True'}), + 'start': ('django.db.models.fields.FloatField', [], {'default': '-1', 'db_index': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}), + 'value': ('django.db.models.fields.TextField', [], {}) + }, + 'auth.group': { + 'Meta': {'object_name': 'Group'}, + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + 'auth.permission': { + 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + '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': '255', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + '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': '255'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}) + }, + 'clip.clip': { + 'Meta': {'unique_together': "(('item', 'start', 'end'),)", 'object_name': 'Clip'}, + 'aspect_ratio': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'descriptions': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'duration': ('django.db.models.fields.FloatField', [], {'default': '0', 'db_index': 'True'}), + 'end': ('django.db.models.fields.FloatField', [], {'default': '-1'}), + 'events': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'findvalue': ('django.db.models.fields.TextField', [], {'null': 'True', 'db_index': 'True'}), + 'hue': ('django.db.models.fields.FloatField', [], {'default': '0', 'db_index': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'item': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'clips'", 'to': "orm['item.Item']"}), + 'keywords': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'lightness': ('django.db.models.fields.FloatField', [], {'default': '0', 'db_index': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'places': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'saturation': ('django.db.models.fields.FloatField', [], {'default': '0', 'db_index': 'True'}), + 'sort': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'matching_clips'", 'to': "orm['item.ItemSort']"}), + 'sortvalue': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'start': ('django.db.models.fields.FloatField', [], {'default': '-1', 'db_index': 'True'}), + 'transcripts': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'user': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'db_index': 'True'}), + 'volume': ('django.db.models.fields.FloatField', [], {'default': '0', 'null': 'True', 'db_index': 'True'}) + }, + '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'}), + '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'}) + }, + 'edit.clip': { + 'Meta': {'object_name': 'Clip'}, + 'annotation': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'editclip'", 'null': 'True', 'to': "orm['annotation.Annotation']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'duration': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'edit': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'clips'", 'to': "orm['edit.Edit']"}), + 'end': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'hue': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'index': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'item': ('django.db.models.fields.related.ForeignKey', [], {'default': 'None', 'related_name': "'editclip'", 'null': 'True', 'to': "orm['item.Item']"}), + 'lightness': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'saturation': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'start': ('django.db.models.fields.FloatField', [], {'default': '0'}), + 'volume': ('django.db.models.fields.FloatField', [], {'default': '0'}) + }, + 'edit.edit': { + 'Meta': {'unique_together': "(('user', 'name'),)", 'object_name': 'Edit'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'description': ('django.db.models.fields.TextField', [], {'default': "''"}), + 'icon': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), + 'poster_frames': ('ox.django.fields.TupleField', [], {'default': '[]'}), + 'rightslevel': ('django.db.models.fields.IntegerField', [], {'default': '0', 'db_index': 'True'}), + 'status': ('django.db.models.fields.CharField', [], {'default': "'private'", 'max_length': '20'}), + 'subscribed_users': ('django.db.models.fields.related.ManyToManyField', [], {'related_name': "'subscribed_edits'", 'symmetrical': 'False', 'to': "orm['auth.User']"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}) + }, + 'edit.position': { + 'Meta': {'unique_together': "(('user', 'edit', 'section'),)", 'object_name': 'Position'}, + 'edit': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'position'", 'to': "orm['edit.Edit']"}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'position': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'section': ('django.db.models.fields.CharField', [], {'max_length': "'255'"}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'edit_position'", 'to': "orm['auth.User']"}) + }, + 'item.item': { + 'Meta': {'object_name': 'Item'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'data': ('ox.django.fields.DictField', [], {'default': '{}'}), + 'external_data': ('ox.django.fields.DictField', [], {'default': '{}'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "'items'", 'blank': 'True', 'to': "orm['auth.Group']"}), + 'icon': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}), + 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'itemId': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128', 'blank': 'True'}), + 'json': ('ox.django.fields.DictField', [], {'default': '{}'}), + 'level': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'oxdbId': ('django.db.models.fields.CharField', [], {'max_length': '42', 'unique': 'True', 'null': 'True', 'blank': 'True'}), + 'poster': ('django.db.models.fields.files.ImageField', [], {'default': 'None', 'max_length': '100', 'blank': 'True'}), + 'poster_frame': ('django.db.models.fields.FloatField', [], {'default': '-1'}), + 'poster_height': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'poster_source': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'poster_width': ('django.db.models.fields.IntegerField', [], {'default': '0'}), + 'rendered': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), + 'stream_aspect': ('django.db.models.fields.FloatField', [], {'default': '1.3333333333333333'}), + 'stream_info': ('ox.django.fields.DictField', [], {'default': '{}'}), + 'torrent': ('django.db.models.fields.files.FileField', [], {'default': 'None', 'max_length': '1000', 'blank': 'True'}), + 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'items'", 'null': 'True', 'to': "orm['auth.User']"}) + }, + 'item.itemsort': { + 'Meta': {'object_name': 'ItemSort'}, + 'accessed': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'aspectratio': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'bitrate': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'cinematographer': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'cutsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'date': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'director': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'duration': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'featuring': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'height': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'hue': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'item': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'sort'", 'unique': 'True', 'primary_key': 'True', 'to': "orm['item.Item']"}), + 'itemId': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'language': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'license': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'lightness': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'location': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'modified': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'numberofannotations': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'numberofcuts': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'numberoffiles': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'pixels': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'project': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'random': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'resolution': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'rightslevel': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'saturation': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'size': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'source': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'timesaccessed': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'title': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'topic': ('django.db.models.fields.CharField', [], {'max_length': '1000', 'null': 'True', 'db_index': 'True'}), + 'volume': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'width': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'words': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), + 'wordsperminute': ('django.db.models.fields.FloatField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}) + } + } + + complete_apps = ['edit'] \ No newline at end of file diff --git a/pandora/edit/models.py b/pandora/edit/models.py index dcd6d00e..59b8c10e 100644 --- a/pandora/edit/models.py +++ b/pandora/edit/models.py @@ -56,6 +56,7 @@ class Edit(models.Model): clip = Clip(edit=self) if 'annotation' in data and data['annotation']: clip.annotation = Annotation.objects.get(public_id=data['annotation']) + clip.item = clip.annotation.item else: clip.item = Item.objects.get(itemId=data['item']) clip.start = data['in'] @@ -297,15 +298,41 @@ class Clip(models.Model): annotation = models.ForeignKey(Annotation, null=True, default=None, related_name='editclip') start = models.FloatField(default=0) end = models.FloatField(default=0) + duration = models.FloatField(default=0) + + hue = models.FloatField(default=0) + saturation= models.FloatField(default=0) + lightness= models.FloatField(default=0) + volume = models.FloatField(default=0) def __unicode__(self): if self.annotation: return u'%s' % self.annotation.public_id return u'%s/%0.3f-%0.3f' % (self.item.itemId, self.start, self.end) + + def get_id(self): + return ox.toAZ(self.id) + + def save(self, *args, **kwargs): + if self.duration != self.end - self.start: + self.update_calculated_values() + super(Clip, self).save(*args, **kwargs) + + def update_calculated_values(self): + start = self.start + end = self.end + self.duration = end - start + if int(end*25) - int(start*25) > 0: + self.hue, self.saturation, self.lightness = extract.average_color( + self.item.timeline_prefix, self.start, self.end) + self.volume = extract.average_volume(self.item.timeline_prefix, self.start, self.end) + else: + self.hue = self.saturation = self.lightness = 0 + self.volume = 0 def json(self, user=None): data = { - 'id': ox.toAZ(self.id), + 'id': self.get_id(), 'index': self.index } if self.annotation: diff --git a/pandora/edit/views.py b/pandora/edit/views.py index d0d50667..365acb9a 100644 --- a/pandora/edit/views.py +++ b/pandora/edit/views.py @@ -120,7 +120,7 @@ def editClip(request): actions.register(editClip, cache=False) @login_required_json -def sortClips(request): +def orderClips(request): ''' takes { edit: string @@ -141,6 +141,48 @@ def sortClips(request): else: response = json_response(status=403, text='permission denied') return render_to_json_response(response) +actions.register(orderClips, cache=False) + +def _order_clips(qs, sort): + order_by = [] + for e in sort: + operator = e['operator'] + if operator != '-': + operator = '' + key = e['key'] + #fixme, random should be clip random + if key not in ('in', 'out', 'position', 'hue', 'saturation', 'lightness', 'volume', 'duration', 'text'): + key = "item__sort__%s" % key + key = { + 'position': 'start', + 'in': 'start', + 'out': 'end', + 'text': 'annotation__sortvalue', + 'item__sort__item': 'item__sort__id', + }.get(key, key) + order = '%s%s' % (operator, key) + order_by.append(order) + if order_by: + qs = qs.order_by(*order_by) + qs = qs.distinct() + return qs + +def sortClips(request): + ''' + takes { + edit: string + sort: obect + } + returns { + } + ''' + data = json.loads(request.POST['data']) + edit = get_edit_or_404_json(data['edit']) + response = json_response() + clips = models.Clip.objects.filter(edit=edit) + clips = _order_clips(clips, data['sort']) + response['data']['clips'] = [ox.toAZ(c['id']) for c in clips.values('id')] + return render_to_json_response(response) actions.register(sortClips, cache=False) def getEdit(request): diff --git a/static/js/pandora/editPanel.js b/static/js/pandora/editPanel.js index 10b3d5b2..fac2ceaf 100644 --- a/static/js/pandora/editPanel.js +++ b/static/js/pandora/editPanel.js @@ -36,7 +36,7 @@ pandora.ui.editPanel = function() { } function render() { - pandora.api.getEdit({id: pandora.user.ui.edit}, function(result) { + pandora.api.getEdit({id: ui.edit}, function(result) { edit = result.data; // fixme: duration should come from backend edit.duration = 0; @@ -128,12 +128,12 @@ pandora.ui.editPanel = function() { }); }, move: function(data) { - pandora.api.sortClips({ + pandora.api.orderClips({ edit: edit.id, ids: data.ids - }, function() { + }, function(result) { Ox.Request.clearCache('getEdit'); - sortClips(data.ids); + orderClips(data.ids); }); }, muted: function(data) { @@ -143,7 +143,7 @@ pandora.ui.editPanel = function() { if (Ox.Clipboard.type() == 'clip') { pandora.api.addClips({ clips: Ox.Clipboard.paste(), - edit: pandora.user.ui.edit + edit: ui.edit }, function(result) { Ox.Request.clearCache('getEdit'); updateClips(edit.clips.concat(result.data.clips)); @@ -160,7 +160,7 @@ pandora.ui.editPanel = function() { if (edit.editable) { pandora.api.removeClips({ ids: data.ids, - edit: pandora.user.ui.edit + edit: ui.edit }, function(result) { Ox.Request.clearCache('getEdit'); updateClips(result.data.clips); @@ -187,7 +187,22 @@ pandora.ui.editPanel = function() { pandora.UI.set('clipSize', data.size); }, sort: function(data) { - pandora.UI.set('clipSort', data.sort); + if (data[0] && data[0].key) { + console.log('S!!!sort', data); + pandora.UI.set('clipSort', data); + pandora.api.sortClips({ + edit: edit.id, + sort: data + }, function(result) { + Ox.print('sort clips', result.data.clips); + //need to also update ClipList + edit.clips.forEach(function(clip) { + clip.sort = result.data.clips.indexOf(clip.id); + }); + edit.clips = Ox.sortBy(edit.clips, 'sort'); + updateVideos(); + }); + } }, subtitles: function(data) { pandora.UI.set('videoSubtitles', data.subtitles); @@ -222,7 +237,7 @@ pandora.ui.editPanel = function() { }); } - function sortClips(ids) { + function orderClips(ids) { edit.clips.forEach(function(clip) { clip.index = ids.indexOf(clip.id); });