浏览代码

HUE-826 [proxy] Embedded proxied app

Changed SDK icons
Fixed create_desktop_app app_dir param
Added iframe proxy app
Enrico Berti 12 年之前
父节点
当前提交
16d8d4f

二进制
desktop/core/src/desktop/app_template/src/app_name/static/art/app_name.png


二进制
desktop/core/src/desktop/app_template/src/app_name/static/art/icon_app_name_24.png


+ 20 - 0
desktop/core/src/desktop/app_template_proxy/Makefile

@@ -0,0 +1,20 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+ifeq ($(ROOT),)
+  $(error "Error: Expect the environment variable $$ROOT to point to the Desktop installation")
+endif
+
+include $(ROOT)/Makefile.sdk

+ 47 - 0
desktop/core/src/desktop/app_template_proxy/setup.py

@@ -0,0 +1,47 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+from setuptools import setup, find_packages
+import os
+
+def expand_package_data(src_dirs, strip=""):
+  ret = []
+  for src_dir in src_dirs:
+    for path, dnames, fnames in os.walk(src_dir):
+      for fname in fnames:
+        ret.append(os.path.join(path, fname).replace(strip, ""))
+  return ret
+
+os.chdir(os.path.dirname(os.path.abspath(__file__)))
+setup(
+  name = "${app_name}",
+  version = "0.1",
+  url = 'TODO',
+  description = 'TODO',
+  author = 'TODO',
+  packages = find_packages('src'),
+  package_dir = {'': 'src'},
+  install_requires = ['setuptools', 'desktop'],
+  entry_points = { 'desktop.sdk.application': '${app_name}=${app_name}' },
+  zip_safe = False,
+  package_data = {
+    # Include static resources.  Package_data doesn't
+    # deal well with directory globs, so we enumerate
+    # the files manually.
+    '${app_name}': expand_package_data(
+      ["src/${app_name}/templates", "src/${app_name}/static"],
+      "src/${app_name}/")
+  }
+)

+ 15 - 0
desktop/core/src/desktop/app_template_proxy/src/__init__.py

@@ -0,0 +1,15 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

+ 15 - 0
desktop/core/src/desktop/app_template_proxy/src/forms.py

@@ -0,0 +1,15 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

+ 15 - 0
desktop/core/src/desktop/app_template_proxy/src/models.py

@@ -0,0 +1,15 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.

+ 19 - 0
desktop/core/src/desktop/app_template_proxy/src/settings.py

@@ -0,0 +1,19 @@
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+DJANGO_APPS = [ "${app_name}" ]
+REQUIRES_HADOOP = False
+MENU_INDEX = 100
+ICON = "/${app_name}/static/art/icon_${app_name}_24.png"

二进制
desktop/core/src/desktop/app_template_proxy/src/static/art/app_name.png


二进制
desktop/core/src/desktop/app_template_proxy/src/static/art/icon_app_name_24.png


+ 1 - 0
desktop/core/src/desktop/app_template_proxy/src/static/help/index.md

@@ -0,0 +1 @@
+Help for your app, written in [MarkDown](http://daringfireball.net/projects/markdown/syntax) syntax.

+ 50 - 0
desktop/core/src/desktop/app_template_proxy/src/templates/index.mako

@@ -0,0 +1,50 @@
+## Licensed to Cloudera, Inc. under one
+## or more contributor license agreements.  See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership.  Cloudera, Inc. licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License.  You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+${'<'}%!from desktop.views import commonheader, commonfooter %>
+${'<'}%namespace name="shared" file="shared_components.mako" />
+
+${'$'}{commonheader("${" ".join(word.capitalize() for word in app_name.split("_"))}", "${app_name}", user, "28px") | n,unicode}
+
+${'#'}# Use double hashes for a mako template comment
+${'#'}# Main body
+
+<style type="text/css">
+  #appframe {
+    width: 100%;
+    border: 0;
+  }
+</style>
+
+<iframe id="appframe" src="${app_url}"></iframe>
+
+<script type="text/javascript">
+  $(document).ready(function () {
+    var _resizeTimeout = -1;
+    $(window).on("resize", function () {
+      console.log("resize")
+      window.clearTimeout(_resizeTimeout);
+      _resizeTimeout = window.setTimeout(resizeAppframe, 300);
+    });
+
+    function resizeAppframe() {
+      $("#appframe").height($(window).height() - 34); // magic: navigator height + safety pixels
+    }
+
+    resizeAppframe();
+  });
+</script>
+
+${'$'}{commonfooter(messages) | n,unicode}

+ 22 - 0
desktop/core/src/desktop/app_template_proxy/src/urls.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('${app_name}',
+  url(r'^$', 'views.index'),
+)

+ 22 - 0
desktop/core/src/desktop/app_template_proxy/src/views.py

@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from desktop.lib.django_util import render
+import datetime
+
+def index(request):
+  return render('index.mako', request, dict(date=datetime.datetime.now()))

+ 1 - 1
desktop/core/src/desktop/management/commands/create_desktop_app.py

@@ -37,7 +37,7 @@ class Command(BaseCommand):
       raise CommandError(_("Expected arguments: app_name [app_dir]"))
     app_name = args[0]
     if len(args) == 2:
-      app_dir = args[0]
+      app_dir = args[1]
     else:
       app_dir = os.getcwd()
 

+ 91 - 0
desktop/core/src/desktop/management/commands/create_proxy_app.py

@@ -0,0 +1,91 @@
+
+# adapted from django-extensions (http://code.google.com/p/django-command-extensions/)
+# Licensed to Cloudera, Inc. under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  Cloudera, Inc. licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os
+import re
+import shutil
+from django.core.management.base import CommandError, BaseCommand
+from mako.template import Template
+
+import logging
+from django.utils.translation import ugettext as _
+
+LOG = logging.getLogger(__name__)
+
+class Command(BaseCommand):
+  help = _("Creates a Hue proxy application directory structure.")
+  args = "[appname]"
+  label = _('application name')
+
+  def handle(self, *args, **options):
+    if len(args) > 3 or len(args) == 0:
+      raise CommandError(_("Expected arguments: app_name [app_url] [app_dir]"))
+    app_name = args[0]
+    if len(args) == 2:
+      app_url = args[1]
+      app_dir = os.getcwd()
+    elif len(args) == 3:
+      app_url = args[1]
+      app_dir = args[2]
+    else:
+      app_url = "http://gethue.com"
+      app_dir = os.getcwd()
+
+    app_template = os.path.abspath(os.path.join(os.path.dirname(__file__),'..','..','app_template_proxy'))
+    assert os.path.isdir(app_template), _("App template dir missing: %(template)s.") % {'template': app_template}
+    app_dir = os.path.join(app_dir, app_name)
+
+    if not os.path.exists(app_template):
+      raise CommandError(_("The template path, %(path)r, does not exist.") % {'path': app_template})
+
+    if not re.search(r'^\w+$', app_name):
+      raise CommandError(_("%(name)r is not a valid application name. Use only numbers, letters and underscores.") % {'name': app_name})
+    try:
+      os.makedirs(app_dir)
+    except OSError, e:
+      raise CommandError(e)
+
+    copy_template(app_template, app_dir, app_name, app_url)
+
+def copy_template(app_template, copy_to, app_name, app_url):
+  """copies the specified template directory to the copy_to location"""
+
+  app_name_spaces = " ".join(word.capitalize() for word in app_name.split("_"))
+  app_name_camel = "".join(word.capitalize() for word in app_name.split("_"))
+
+  # walks the template structure and copies it
+  for directory, subdirs, files in os.walk(app_template):
+    relative_dir = directory[len(app_template)+1:].replace('app_name_camel', app_name_camel).replace('app_name',app_name)
+    if not os.path.exists(os.path.join(copy_to, relative_dir)):
+      os.mkdir(os.path.join(copy_to, relative_dir))
+    for f in files:
+      if f.endswith('.pyc') or f.startswith("."):
+        continue
+        
+      path_old = os.path.join(directory, f)
+      path_new = os.path.join(copy_to, relative_dir, f.replace('app_name_camel', app_name_camel).replace('app_name', app_name))
+
+      LOG.info("Writing %s" % path_new)
+      fp_new = open(path_new, 'w')
+      if path_old.endswith(".png"):
+        shutil.copyfileobj(file(path_old), fp_new)
+      else:
+        fp_new.write( Template(filename=path_old).render(app_name=app_name, app_name_camel=app_name_camel, app_name_spaces=app_name_spaces, app_url=app_url) )
+      fp_new.close()
+        
+      shutil.copymode(path_old, path_new)