Merge branch 'master' of git@github.com:zalun/FlightDeck

This commit is contained in:
Piotr Zalewa 2010-03-06 16:03:00 +00:00
Родитель d5331ec980 b75ebf900c
Коммит ad115d5163
10 изменённых файлов: 116 добавлений и 55 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -83,10 +83,6 @@ body {
.UI_Browser .UI_Actions {
margin: 14px 0 0;
/* position: absolute;
top: 0;
right: 0;
*/
}
.UI_Browser .UI_Actions li {

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
},
/*

Просмотреть файл

@ -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

Просмотреть файл

@ -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 }}',

Просмотреть файл

@ -0,0 +1,2 @@
{"get_xpi_url": "{{ xpi_url }}"}

Просмотреть файл

@ -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<hash>.*)/(?P<filename>.*)/$', 'getXPI', name='get_xpi'),
url(r'^create_xpi/$', 'createXPI', name='jp_create_xpi'),
url(r'^get_xpi/(?P<hash>.*)/(?P<slug>.*)/$', 'getXPI', name='jp_get_xpi'),
url(r'^jp_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/$',
url(r'^ext_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/$',
'jetpack_version_edit', name='jp_jetpack_version_edit'),
url(r'^mod_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/$',
'capability_version_edit', name='jp_capability_version_edit'),
url(r'^jp_(?P<slug>.*)/version_create/$',
url(r'^ext_(?P<slug>.*)/version_create/$',
'item_version_create', {"type": "jetpack"}, name='jp_jetpack_version_create'),
url(r'^mod_(?P<slug>.*)/version_create/$',
'item_version_create', {"type": "capability"}, name='jp_capability_version_create'),
url(r'^jp_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/update/$',
url(r'^ext_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/update/$',
'item_version_update', {"type": "jetpack"}, name='jp_jetpack_version_update'),
url(r'^mod_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/update/$',
'item_version_update', {"type": "capability"}, name='jp_capability_version_update'),
url(r'^jp_(?P<slug>.*)/update/$',
url(r'^ext_(?P<slug>.*)/update/$',
'item_update', {"type": "jetpack"}, name='jp_jetpack_update'),
url(r'^mod_(?P<slug>.*)/update/$',
'item_update', {"type": "capability"}, name='jp_capability_update'),
url(r'^jp_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/add_dependency/$',
url(r'^ext_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/add_dependency/$',
'add_dependency', {'type': 'jetpack'}, name='jp_jetpack_add_dependency'),
url(r'^mod_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/add_dependency/$',
'add_dependency', {'type': 'capability'}, name='jp_capability_add_dependency'),
url(r'^jp_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/remove_dependency/(?P<d_slug>.*)/(?P<d_version>.*)/(?P<d_counter>\d+)/$',
url(r'^ext_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/remove_dependency/(?P<d_slug>.*)/(?P<d_version>.*)/(?P<d_counter>\d+)/$',
'remove_dependency', {'type': 'jetpack'}, name='jp_jetpack_remove_dependency'),
url(r'^cap_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/remove_dependency/(?P<d_slug>.*)/(?P<d_version>.*)/(?P<d_counter>\d+)/$',
'remove_dependency', {'type': 'capability'}, name='jp_capability_remove_dependency'),
url(r'^jp_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/save_as_base/$',
url(r'^ext_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\d+)/save_as_base/$',
'item_version_save_as_base', {'type': 'jetpack'},
name='jp_jetpack_version_save_as_base'),
url(r'^mod_(?P<slug>.*)/v_(?P<version>.*)\.(?P<counter>\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<slug>.*)/$',
url(r'^ext_(?P<slug>.*)/$',
'jetpack_edit', name='jp_jetpack_edit'),
url(r'^mod_(?P<slug>.*)/$',
'capability_edit', name='jp_capability_edit'),

Просмотреть файл

@ -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
"""