diff --git a/Docs/data_structure.txt b/Docs/data_structure.txt index 7d063ba1..f99baea2 100644 --- a/Docs/data_structure.txt +++ b/Docs/data_structure.txt @@ -10,15 +10,16 @@ EXTENSION, MODULES | version.manifest | package.json | | version.description | --- | | version.name+.counter | version | +| version[i].author | pkg.contributors[j] | | capabilities[i].slug | lib/filename.js, pkg.dependencies[i] | | capabilities[i].content | content of filename.js | -| capabilities[i].author | pkg.contributors[j] | `-----------------------------------------------------------------------' Following data stays in FilghtDeck and is never used outside + * capability.creator * capability.name * capability.description * capability.version.name * capability.version.counter * capability.version.description - + * capability.version.author diff --git a/flightdeck/jetpack/media/css/UI.Browser.css b/flightdeck/jetpack/media/css/UI.Browser.css index 1ddbb73d..a0318478 100644 --- a/flightdeck/jetpack/media/css/UI.Browser.css +++ b/flightdeck/jetpack/media/css/UI.Browser.css @@ -83,10 +83,6 @@ body { .UI_Browser .UI_Actions { margin: 14px 0 0; -/* position: absolute; - top: 0; - right: 0; -*/ } .UI_Browser .UI_Actions li { diff --git a/flightdeck/jetpack/media/css/UI.Layout.css b/flightdeck/jetpack/media/css/UI.Layout.css index dadd92b4..fd3d0493 100644 --- a/flightdeck/jetpack/media/css/UI.Layout.css +++ b/flightdeck/jetpack/media/css/UI.Layout.css @@ -35,8 +35,8 @@ a:hover { /* =========================================================================== */ #app-header { - background: -moz-linear-gradient(270deg, #424A52, #4E5861); - height: 90px; + background: -moz-linear-gradient(270deg, #545F6B, #4E5861); + height: 60px; } #app-header nav { @@ -78,7 +78,7 @@ a:hover { } #app-header nav li.active span { - background: -moz-linear-gradient(270deg, #59A1F2, #1C5AAB); + background: -moz-linear-gradient(270deg, #66778C, #545F6B); -moz-border-radius: 2px; padding: 4px 8px; display: inline-block; @@ -97,6 +97,8 @@ a:hover { position: absolute; top: 20px; left: 10px; + + display: none; } #mozillalabs-logo a { diff --git a/flightdeck/jetpack/media/js/CapDependency.js b/flightdeck/jetpack/media/js/CapDependency.js index 63725b07..83130264 100644 --- a/flightdeck/jetpack/media/js/CapDependency.js +++ b/flightdeck/jetpack/media/js/CapDependency.js @@ -39,12 +39,20 @@ var CapDependency = new Class({ fd.message.alert(response.message); // change id's on the elements }, + prepareData: function() { + var data = $H({ + name: this.options.name, + slug: this.options.slug, + creator: this.options.creator + }); + data.extend(this.version.prepareData()); + return data.getClean(); + }, instantiateEditors: $empty, initializeEditorSwitches: $empty, switchToDescription: $empty, try_in_browser: $empty, - getContent: $empty, - prepareData: $empty + getContent: $empty }); var CapVersionDependency = new Class({ @@ -60,7 +68,8 @@ var CapVersionDependency = new Class({ this.initializeEditorSwitches(); this.data = $H({ version_name: this.options.name, - versin_description: this.options.description, + version_counter: this.options.counter, + version_description: this.options.description, version_content: this.options.content }); }, @@ -114,6 +123,10 @@ var CapVersionDependency = new Class({ updateFromDOM: function() { this.data.version_content = this.content_el.getContent(); }, + prepareData: function() { + this.updateFromDOM(); + return this.data; + }, setAsBase: $empty, switchToDescription: $empty, getName: $empty diff --git a/flightdeck/jetpack/media/js/Capability.js b/flightdeck/jetpack/media/js/Capability.js index 2a4a0bd5..9d3b60e9 100644 --- a/flightdeck/jetpack/media/js/Capability.js +++ b/flightdeck/jetpack/media/js/Capability.js @@ -23,7 +23,6 @@ var Capability = new Class({ //switch_description_id: '', update_el: 'update', version_create_el: 'version_create', - try_in_browser_el: 'try_in_browser', //edit_url: '', //update_url: '', //version_create_url: '', @@ -89,14 +88,6 @@ var Capability = new Class({ this.createAfterBounds(); this.version.addEvent('change', this.boundAfterVersionChanged); this.description_el.addEvent('change', this.boundAfterDataChanged); - // one may try even not edited data - var try_in_browser_el = $(this.options.try_in_browser_el) - if (try_in_browser_el) { - try_in_browser_el.addEvent('click', function(e) { - e.stop(); - this.try_in_browser(); - }.bind(this)); - } var switch_version_el = $('switch_to_version'); if (switch_version_el) { switch_version_el.addEvent('change', function() { @@ -171,15 +162,6 @@ var Capability = new Class({ afterVersionCreated: function(response) { window.location.href = response.version_absolute_url; }, - /* - * Method: try_in_browser - * Prepare Capability using saved content and install temporary in the browser - */ - try_in_browser: function() { - var data = this.getFullData(); - fd.warning.alert('Not implemented','try_in_browser'); - console.log(data); - }, /* * Method: getContent * Wrapper for getting content from the Editor @@ -462,14 +444,10 @@ var CapVersion = new Class({ prepareData: function() { this.updateFromDOM(); // prepare capability info - var get_id = function(cap) { - return { - 'slug': cap.options.slug, - 'version': cap.version.options.name, - 'counter': cap.version.options.counter - } + var get_data = function(cap) { + return cap.prepareData(); } - this.data['capabilities'] = JSON.encode($H(this.capabilities).getValues().map(get_id)); + this.data['capabilities'] = JSON.encode($H(this.capabilities).getValues().map(get_data)); return this.data; }, /* diff --git a/flightdeck/jetpack/media/js/Jetpack.js b/flightdeck/jetpack/media/js/Jetpack.js index 8edc2954..9520f7cd 100644 --- a/flightdeck/jetpack/media/js/Jetpack.js +++ b/flightdeck/jetpack/media/js/Jetpack.js @@ -7,7 +7,8 @@ var Jetpack = new Class({ type: 'jetpack', options: { description_el: {element: 'jetpack_description'}, - try_in_browser_el: 'try_in_browser' + try_in_browser_el: 'try_in_browser', + // try_in_browser_url: '' }, /* * Method: initialize @@ -25,6 +26,40 @@ var Jetpack = new Class({ } this.parent(this.options); }, + + listenToEvents: function() { + this.parent(); + // one may try even not edited data + var try_in_browser_el = $(this.options.try_in_browser_el) + if (try_in_browser_el) { + try_in_browser_el.addEvent('click', function(e) { + e.stop(); + this.try_in_browser(); + }.bind(this)); + } + }, + /* + * Method: try_in_browser + * Prepare Capability using saved content and install temporary in the browser + */ + try_in_browser: function() { + var data = this.getFullData(); + //fd.warning.alert('Not implemented','try_in_browser'); + new Request.JSON({ + url: this.options.try_in_browser_url, + method: 'post', + data: data, + onSuccess: function(respose) { + fd.message('Debug','XPI created - sending data to Fd addon'); + // now call the add-on + $log(response); + this.install_xpi(); + }.bind(this) + }).send(); + }, + install_xpi: function(url) { + $log(url) + }, /* * Method: initializeVersion * assigns JetVersion to this.version diff --git a/flightdeck/jetpack/templates/js/_edit_item_initiate.js b/flightdeck/jetpack/templates/js/_edit_item_initiate.js index 14c2cacf..d8832cb4 100644 --- a/flightdeck/jetpack/templates/js/_edit_item_initiate.js +++ b/flightdeck/jetpack/templates/js/_edit_item_initiate.js @@ -9,6 +9,9 @@ item = new {{ type|capfirst }}({ update_url: '{{ item.get_update_url }}', version_create_url: '{{ item.get_version_create_url }}', switch_description_id: '{{ item|tab_link_id:"description" }}', + {% ifequal type 'jetpack' %} + try_in_browser_url: '{% url jp_create_xpi %}', + {% endifequal %} version: { {% ifequal type 'jetpack' %} manifest: '{{ version.manifest|escapejs }}', diff --git a/flightdeck/jetpack/templates/json/xpi_created.json b/flightdeck/jetpack/templates/json/xpi_created.json new file mode 100644 index 00000000..e7012d08 --- /dev/null +++ b/flightdeck/jetpack/templates/json/xpi_created.json @@ -0,0 +1,2 @@ +{"get_xpi_url": "{{ xpi_url }}"} + diff --git a/flightdeck/jetpack/urls.py b/flightdeck/jetpack/urls.py index a06e2330..974b44d8 100644 --- a/flightdeck/jetpack/urls.py +++ b/flightdeck/jetpack/urls.py @@ -3,52 +3,52 @@ from django.conf.urls.defaults import * urlpatterns = patterns('jetpack.views', url(r'^gallery/$', 'gallery', name='gallery'), - url(r'^create_xpi/$', 'createXPI', name='create_xpi'), - url(r'^get_xpi/(?P.*)/(?P.*)/$', 'getXPI', name='get_xpi'), + url(r'^create_xpi/$', 'createXPI', name='jp_create_xpi'), + url(r'^get_xpi/(?P.*)/(?P.*)/$', 'getXPI', name='jp_get_xpi'), - url(r'^jp_(?P.*)/v_(?P.*)\.(?P\d+)/$', + url(r'^ext_(?P.*)/v_(?P.*)\.(?P\d+)/$', 'jetpack_version_edit', name='jp_jetpack_version_edit'), url(r'^mod_(?P.*)/v_(?P.*)\.(?P\d+)/$', 'capability_version_edit', name='jp_capability_version_edit'), - url(r'^jp_(?P.*)/version_create/$', + url(r'^ext_(?P.*)/version_create/$', 'item_version_create', {"type": "jetpack"}, name='jp_jetpack_version_create'), url(r'^mod_(?P.*)/version_create/$', 'item_version_create', {"type": "capability"}, name='jp_capability_version_create'), - url(r'^jp_(?P.*)/v_(?P.*)\.(?P\d+)/update/$', + url(r'^ext_(?P.*)/v_(?P.*)\.(?P\d+)/update/$', 'item_version_update', {"type": "jetpack"}, name='jp_jetpack_version_update'), url(r'^mod_(?P.*)/v_(?P.*)\.(?P\d+)/update/$', 'item_version_update', {"type": "capability"}, name='jp_capability_version_update'), - url(r'^jp_(?P.*)/update/$', + url(r'^ext_(?P.*)/update/$', 'item_update', {"type": "jetpack"}, name='jp_jetpack_update'), url(r'^mod_(?P.*)/update/$', 'item_update', {"type": "capability"}, name='jp_capability_update'), - url(r'^jp_(?P.*)/v_(?P.*)\.(?P\d+)/add_dependency/$', + url(r'^ext_(?P.*)/v_(?P.*)\.(?P\d+)/add_dependency/$', 'add_dependency', {'type': 'jetpack'}, name='jp_jetpack_add_dependency'), url(r'^mod_(?P.*)/v_(?P.*)\.(?P\d+)/add_dependency/$', 'add_dependency', {'type': 'capability'}, name='jp_capability_add_dependency'), - url(r'^jp_(?P.*)/v_(?P.*)\.(?P\d+)/remove_dependency/(?P.*)/(?P.*)/(?P\d+)/$', + url(r'^ext_(?P.*)/v_(?P.*)\.(?P\d+)/remove_dependency/(?P.*)/(?P.*)/(?P\d+)/$', 'remove_dependency', {'type': 'jetpack'}, name='jp_jetpack_remove_dependency'), url(r'^cap_(?P.*)/v_(?P.*)\.(?P\d+)/remove_dependency/(?P.*)/(?P.*)/(?P\d+)/$', 'remove_dependency', {'type': 'capability'}, name='jp_capability_remove_dependency'), - url(r'^jp_(?P.*)/v_(?P.*)\.(?P\d+)/save_as_base/$', + url(r'^ext_(?P.*)/v_(?P.*)\.(?P\d+)/save_as_base/$', 'item_version_save_as_base', {'type': 'jetpack'}, name='jp_jetpack_version_save_as_base'), url(r'^mod_(?P.*)/v_(?P.*)\.(?P\d+)/save_as_base/$', 'item_version_save_as_base', {"type": "capability"}, name='jp_capability_version_save_as_base'), - url(r'^jp/create', + url(r'^ext/create', 'item_create', {"type": "jetpack"}, name='jp_jetpack_create'), url(r'^cap/create', 'item_create', {"type": "capability"}, name='jp_capability_create'), - url(r'^jp_(?P.*)/$', + url(r'^ext_(?P.*)/$', 'jetpack_edit', name='jp_jetpack_edit'), url(r'^mod_(?P.*)/$', 'capability_edit', name='jp_capability_edit'), diff --git a/flightdeck/jetpack/views.py b/flightdeck/jetpack/views.py index dd9827be..16d330ea 100644 --- a/flightdeck/jetpack/views.py +++ b/flightdeck/jetpack/views.py @@ -1,3 +1,5 @@ +import os + from django.core.urlresolvers import reverse from django.shortcuts import render_to_response, get_object_or_404 from django.http import Http404, HttpResponseRedirect, HttpResponse, \ @@ -314,18 +316,47 @@ def createXPI(r): Data will be cleaned by cron every x minutes """ # all data has to be provided by POST + slug = r.POST.get('jetpack_slug') + main = r.POST.get('version_content') + description = r.POST.get('jetpack_description') + package = r.POST.get('version_manifest') + libs = simplejson.loads(r.POST.get('capabilities')) + + # create random hash + from random import choice + allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789' + hash = 'jetpack-' + ''.join([choice(allowed_chars) for i in range(10)]) # first create file structure + os.mkdir ('/tmp/%s' % hash) + if libs: + os.mkdir('/tmp/%s/lib' % hash) + + for lib in libs: + libHandle = open('/tmp/%s/lib/%s.js' % (hash, lib['slug']), 'w') + libHandle.write(lib['version_content']) + libHandle.close() + + pkgHandle = open('/tmp/%s/package.json' %hash, 'w') + pkgHandle.write(package) + pkgHandle.close() + + mainHandle = open('/tmp/%s/lib/main.js' % hash, 'w') + mainHandle.write(main) + mainHandle.close() + + descHandle = open('/tmp/%s/README.md' % hash, 'w') + descHandle.write(description) + descHandle.close() + # save the directory using the hash only import subprocess try: - subprocess.check_call('cfx', - '--binary=/usr/bin/xulrunner', - '--pkgdir=%s' % dirname, - 'xpi') + print 'cfx --binary=/usr/bin/xulrunner --pkgdir=/tmp/%s xpi' % hash + subprocess.check_call('cfx --binary=/usr/bin/xulrunner --pkgdir=/tmp/%s xpi' % hash) except subprocess.CalledProcessError: return HttpResponseServerError - + xpi_url = reverse('jp_get_xpi', args=[hash, slug]) # return hash and xpi filename return render_to_response('json/xpi_created.json', {'url':xpi_url}, @@ -333,7 +364,7 @@ def createXPI(r): mimetype='application/json') -def getXPI(r, hash, filename): +def getXPI(r, hash, slug): """ return XPI file """