Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shopfloor_mobile: REF index to render app w/ qweb template #82

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shopfloor_mobile/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"category": "Warehouse Management",
"license": "AGPL-3",
"installable": True,
"data": ["menus.xml"],
"data": ["menus.xml", "templates/main.xml", "templates/assets.xml"],
}
152 changes: 134 additions & 18 deletions shopfloor_mobile/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,147 @@
import json
import os

from odoo import http
from odoo.modules.module import load_information_from_description_file

APP_VERSIONS = {}

class ShopfloorMobileAppController(http.Controller):

class ShopfloorMobileAppMixin(object):

module_path = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
main_template = "shopfloor_mobile.shopfloor_app_main"

@http.route(
[
"/shopfloormobile/scanner/<path:path_fragment>",
"/shopfloormobile/scanner",
"/shopfloormobile/scanner/demo",
"/shopfloormobile/scanner/demo/<path:path_fragment>",
],
auth="public",
)
def load_app_and_assets(self, path_fragment=""):
def _load_app(self, demo=False):
return http.request.render(
self.main_template, self._get_main_template_values(demo=demo)
)

def _get_main_template_values(self, demo=False):
return {
"app_version": self._get_app_version(),
"get_version": self._get_version,
"demo_mode": demo,
}

def _get_version(self, module_name, module_path=None):
"""Return module version straight from manifest."""
global APP_VERSIONS
if APP_VERSIONS.get(module_name):
return APP_VERSIONS[module_name]
try:
info = load_information_from_description_file(
module_name, mod_path=module_path
)
APP_VERSIONS[module_name] = info["version"]
return APP_VERSIONS[module_name]
except Exception:
return "dev"

def _get_app_version(self):
return self._get_version("shopfloor_mobile", module_path=self.module_path)

def _serve_assets(self, path_fragment=""):
# TODO Should be authorized via api.key except for the login ?
if path_fragment.endswith((".js.map", "scriptElement")):
# `js.map` -> JS maps called by debugger
if path_fragment.endswith((".map", "scriptElement")):
# `.map` -> .map maps called by debugger
# `scriptElement` -> file imported via JS but not loaded
return http.request.not_found()
if path_fragment.startswith("src/"):
# Serving an asset
payload = os.path.join(self.module_path, "static", "wms", path_fragment)
else:
# Serving the app
payload = os.path.join(self.module_path, "static", "wms", "index.html")
return http.send_file(payload)
payload = self._make_asset_path(path_fragment)
if os.path.exists(payload):
return http.send_file(payload)
return http.request.not_found()

def _make_asset_path(self, path_fragment):
return os.path.join(self.module_path, "static", "wms", path_fragment)

def _make_icons(self, fname, rel, sizes, img_type, url_pattern=None):
app_version = self._get_app_version()
all_icons = []
url_pattern = url_pattern or (
"/shopfloor_mobile/assets/"
"src/assets/icons/{fname}-{size}.png?{app_version}"
)
for size in sizes:
all_icons.append(
{
"rel": rel,
"src": url_pattern.format(
app_version=app_version, fname=fname, size=size
),
"sizes": size,
"type": img_type,
}
)
return all_icons

def _get_app_icons(self):
all_icons = []
# apple icons
rel = "apple-touch-icon"
sizes = (
"57x57",
"60x60",
"72x72",
"76x76",
"114x114",
"120x120",
"144x144",
"152x152",
"180x180",
)
fname = "apple-icon"
img_type = "image/png"
all_icons.extend(self._make_icons(fname, rel, sizes, img_type))
# android icons
rel = "icon"
sizes = ("48x48", "72x72", "96x96", "144x144", "192x192")
fname = "android-icon"
img_type = "image/png"
all_icons.extend(self._make_icons(fname, rel, sizes, img_type))
# favicons
rel = "icon"
sizes = ("16x16", "32x32", "96x96")
fname = "favicon"
img_type = "image/png"
all_icons.extend(self._make_icons(fname, rel, sizes, img_type))
return all_icons

def _get_manifest(self):
return {
"name": "Shopfloor WMS app",
"short_name": "Shopfloor",
"start_url": "/shopfloor/app/#",
"display": "fullscreen",
"icons": self._get_app_icons(),
}


class ShopfloorMobileAppController(http.Controller, ShopfloorMobileAppMixin):
@http.route(
["/shopfloor_mobile/app", "/shopfloor_mobile/app/<string:demo>"], auth="public",
)
def load_app(self, demo=False):
return self._load_app(demo=True if demo else False)

@http.route(
["/shopfloormobile/scanner"], auth="public",
)
def load_app_backward(self, demo=False):
# Backward compat redirect (url changed from /scanner to /app)
return http.redirect_with_hash("/shopfloor_mobile/app", code=301)

@http.route(
["/shopfloor_mobile/assets/<path:path_fragment>"], auth="public",
)
def load_assets(self, path_fragment=""):
return self._serve_assets(path_fragment=path_fragment)

@http.route("/shopfloor_mobile/manifest.json", auth="public")
def manifest(self):
manifest = self._get_manifest()
headers = {}
headers["Content-Type"] = "application/json"
return http.request.make_response(json.dumps(manifest), headers=headers)
4 changes: 2 additions & 2 deletions shopfloor_mobile/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<odoo>
<record id="action_shopfloor_app" model="ir.actions.act_url">
<field name="name">Shopfloor mobile app</field>
<field name="url">/shopfloormobile/scanner/#</field>
<field name="url">/shopfloor_mobile/app/#</field>
<field name="target">new</field>
</record>
<record id="action_shopfloor_app_demo" model="ir.actions.act_url">
<field name="name">Shopfloor mobile app DEMO</field>
<field name="url">/shopfloormobile/scanner/demo/#</field>
<field name="url">/shopfloor_mobile/app/demo/#</field>
<field name="target">new</field>
</record>
<menuitem
Expand Down
97 changes: 0 additions & 97 deletions shopfloor_mobile/static/wms/index.html

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion shopfloor_mobile/static/wms/src/components/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Vue.component("nav-items-extra", {
{
id: "settings",
name: "Settings",
icon: "mdi-settings-outline",
icon: "mdi-cog-outline",
route: {name: "settings"},
},
];
Expand Down
451 changes: 451 additions & 0 deletions shopfloor_mobile/static/wms/src/css/vendor/google-fonts-roboto.css

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions shopfloor_mobile/static/wms/src/homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export var HomePage = Vue.component("home-page", {
</v-col>
</v-row>
</div>

<v-footer absolute padless>
<v-col class="text-center font-weight-light" cols="12">
<span class="version">Version:</span> <span class="version-number" v-text="$root.app_info.app_version" />
</v-col>
</v-footer>
</Screen>
`,
});
48 changes: 0 additions & 48 deletions shopfloor_mobile/static/wms/src/lib/fonts/roboto.css

This file was deleted.

Loading