forked from OCA/wms
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from camptocamp/version-mgmt
shopfloor_mobile: REF index to render app w/ qweb template
- Loading branch information
Showing
45 changed files
with
874 additions
and
27,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
shopfloor_mobile/static/wms/src/assets/icons/android-icon-192x192.png
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 added
BIN
+10.9 KB
shopfloor_mobile/static/wms/src/assets/icons/apple-icon-precomposed.png
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
451 changes: 451 additions & 0 deletions
451
shopfloor_mobile/static/wms/src/css/vendor/google-fonts-roboto.css
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.