Integration of Ionic framework and nw.js - angularjs

I am going to build a nw.js (node webkit) app for portability (Mac and Windows). As I'd like the app to run on mobile devices (iOS and Android) later, I use Ionic framework. As suggested by Ionic folks, it's better to keep two sets of views, one for Ionic (mobile) and one for nw.js (desktop). Hopefully I can share codes in the controller and factory.
So, here is what I do:
1) Create a Ionic skeleton project:
ionic start --appname Hello Hello sidemenu
cd Hello
ionic serve
...
quit
2) Create an entry point html for nw.js and setup the manifest:
cd www
cp index.html app.html
and remove the following cordova-specific lines in app.html:
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
then create a package.json:
{
"name": "hello",
"version": "1.0.0",
"description": "Hello World",
"main": "app.html",
"window": {
"title": "Hello",
"toolbar": true,
"frame": false,
"width": 800,
"height": 600,
"position": "mouse",
"min_width": 400,
"min_height": 200,
"max_width": 800,
"max_height": 600
},
"webkit": {
"plugin": true
},
"author": "Horace Ho"
}
and run the app in node webkit:
nw .
Basically I created app.html and package.json in the www folder of an Ionic skeleton project. Now I have a nw.js skeleton project with both Ionic and angular frameworks.
My question is, does the above make sense? As long as there are two entry points (index.html for Ionic, app.html for nw.js), is it safe to add unrelated html/css/js within the www folder of Ionic? To further extend, I may replace Ionic by Bootstrap and leave only AngularJS codes (controller and factory) to be shared between the mobile and desktop apps.

Ionic is clearly mobile centric, so you would have to make at least some trade-offs on your desktop UI. Having two entry points will clearly solve this, and it will be safe (albeit not efficient) to have two separate html/css/js for both. However, I'd suggest to identify as much common code as possible at least for css/js and use it for both. Try to use sass/scss instead of plain css if possible.
If you want to have a single UI for both desktop and mobile, I'd suggest to have a look at angular material. I am currently developing a desktop/tablet app with it, for which it works very well, but angular material is clearly mobile first or at least very suitable for mobile. This makes it imho a better choice for mobile than Bootstrap, which I regard as desktop first.

Related

Ionic 5, different files for PWA and native builds

I want to use the same code-base for my Website and native mobile apps. I am building the native apps using ionic cordova build <platform> and deploying the website with ionic serve --external --prod inside a docker. I need toh convert the bottom-tab navigation bar on my app to a sidebar on my website. This will require change in routing and HTML files. But all the other files which we are displaying remain the same. So, How do i deploy different files for my website and different ones for my native app on every version?
Ionic Platform service
You could use the Ionic Platform
service to
determine the platform of the user's current device, then based on
different platforms, display your desired template using *ngIf
directive
TS file
import { Platform } from '#ionic/angular';
#Component({...})
export class MyPage {
is_native: boolean;
is_pwa: boolean;
constructor(public platform: Platform) {
this.is_native = this.platform.is('hybrid');
this.is_pwa = this.platform.is('pwa');
}
}
HTML template
<div #sideMenu *ngIf="is_pwa">...
</div>
<div #navBar *ngIf="is_native">...
</div>
Updated: Shell script
Another way is to replace your template files with different ones using shell scripts.
cp src/app/componenets/template.pwa.html src/app/componenets/template.html
ionic serve --external --prod

Challenges with Production Build

Step 1
sencha -sdk C:/Users/lperepol/Downloads/SenchaEnterpriseExtJS/Unzip_7.xx/ext-7.3.1/ext-7.3.1 generate app -ext CDW ./CDW
Step 2
sencha app build
Then move the production folder to Web Server. App displays fine.
Step 3
Add a chart.
sencha app watch -- Chart displays fine.
Step 4
sencha app build
Then move the production folder to Web Server. App does not display web server error.
How do I get charts to display on a production web server? In development, everything works but not when moved to a Web Server.
Thank you for the response that led me in the right direction! Adding items to the requires array in the chart view solved the issue. The charts are displaying now on a remote web server --> CDW
requires: [
'Ext.chart.CartesianChart',
'Ext.chart.axis.Category3D',
'Ext.chart.axis.Numeric3D',
'Ext.chart.grid.HorizontalGrid3D',
'Ext.chart.grid.VerticalGrid3D'
'Ext.chart.interactions.ItemHighlight',
'Ext.chart.interactions.PanZoom',
'Ext.chart.series.Bar3D',
'Ext.chart.series.Line',
'Ext.chart.theme.*',
'Ext.draw.modifier.Highlight',
],
make sure in your app.json you have:
Charts in the requires section.
"requires": [
"exporter#7.3.1",
"calendar#7.3.1",
"charts#7.3.1",
"font-awesome"
],
a manifest defined in the bootstrap property.
The bootstrap section should be there but you may have to add the manifest property.
"bootstrap": {
"base": "${app.dir}",
"manifest": {
"path": "bootstrap.json",
"exclude": ""
},
"microloader": "bootstrap.js",
"css": "bootstrap.css"
},

Where to put ng1 templates in an angular hybrid application built by angular-cli?

I'm trying to build an angular hybrid application out of a angular.js application. I'm following the official documentation (https://angular.io/guide/upgrade). I reached and completed this step: https://angular.io/guide/upgrade#bootstrapping-hybrid-applications.
I'm using angular ui-router 0.3.1 to handle the routing of my application. Therefore, using the config function on my main module, and the $stateProvider service, I've mapped each route to an angular.js controller and a template specified by the templateUrl parameter.
My application seems to startup correctly but the templates cannot be loaded because they cannot be found (404 error). This is normal because they are not imported in the dist folder where my application is built when I use the ng build angular-cli command line.
How can I configure my application so that my angular.js html templates get copied in the dist folder when my angluar application is built by angular-cli?
Thanks in advance!
So actually it appears my question was a duplicate of that one: Angular CLI with Hybrid app ng-build.
The idea is to use the assets array from angular-cli.json. Glob enables to select recursively all html files from the folder of your choice and to put them in a subfolder of dist:
"asssets": [{"glob": "**/*.html", "input": "../src-ng1", "output": "./src-ng1"}]

Polymer - two browsers on same machine

I noticed this in my custom app, but it applies to the Polymer starter kit as well. I have two browsers open, Chrome and Firefox, and a click on one browser in my Polymer app affects the other.
Why?
How?!!
(Chrome on left, Firefox on right. Clicking in Firefox affects Chrome!)
Edit: And my phone?!!
This was due to how the page was served. Polymer Starter Kit has a gulp file setup to server and auto-reload the pages. Works great! But I guess it also keeps things perfectly in sync. Great for development : )
Serving with something else (live-server) allowed the app to function as expected.
Edit: As #chillitom mentioned in the comments, it was BrowserSync. When I start using gulp serve I see this:
[PSK] Access URLs:
--------------------------------------
Local: http://localhost:5000
External: http://192.168.1.107:5000
--------------------------------------
UI: http://localhost:3002
UI External: http://192.168.1.107:3002
--------------------------------------
Going to http://localhost:3002 allowed me to change browser sync options, and that "fixed" this as well.

AngularJs/Yeoman/Grunt Play Framework blank page

Today I decided to try out AngularJs with play framework, I've created a folder inside my public folder called AngularJs, in which i have generated an angular app with yeoman.
After generating the sources with grunt build, in the route folder of play, I've put:
GET / controllers.Assets.at(path="/public/javascripts/angularJs/src/dist", file="index.html")
Now the problem I am facing is that the index page is well retrieved but Angular doesn't load the templates.
Anyone have a clue?
Ok now I get it after fiddling around for a moment, the problem with angularJs and Play framework, is that play must serv all the angularJS resources, so the solution to the problem, is to create routes to the angularJs dist folder in your public play application folder.
for an angularJs application created with Yeoman and generated using "grunt build", you must define these routes :
GET /scripts/*Asset controllers.Assets.at(path="/public/javascripts/angularJs/scripts", Asset)
GET /views/*Asset controllers.Assets.at(path="/public/javascripts/angularJs/views", Asset)

Resources