Commit ed2f73b9 by Tuukka Kivilahti

menu navigation

1 parent 8c88b25b
Showing with 214 additions and 21 deletions
...@@ -15,6 +15,33 @@ Jos tulee muita järkeviä kokonaisuuksia, joita voi käyttää muualla, jaa oma ...@@ -15,6 +15,33 @@ Jos tulee muita järkeviä kokonaisuuksia, joita voi käyttää muualla, jaa oma
## TODO
Tekemistä jota voi esim kämpissä säätää
### I18N
I18N loaderi webpackkiin. Esim. muuntaa properties-filun taulukoksi ja siihen joku localisointikirjasto, tai jotain.
### Paketointi
Miten paketoidaan moya niin että mukaan kääntyy myös angular -jutukkeet?
### Lazy loading
Lazy loading niin että se toimii vielä moyan kanssa, vaatinnee säätöä.
### Travis yms. autotestit
oma travis-palvelin, ja siihen autotestit
Ehkä greenkeeper, jos sitä voi hostata ite
### Testit
Integraatio jne. testit, aloitteliat ei riko asioita niin todennäköisesti.
### WebPack ja buildin minimointi
aot-kääntäminen ja siihen comperssointia jne.
# MoyaAngular, generoidut ohjeet # MoyaAngular, generoidut ohjeet
This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.24. This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.24.
......
import { Component } from '@angular/core'; import {Component, NgZone} from '@angular/core';
import {Router} from "@angular/router"; import {Router} from "@angular/router";
declare var window: any;
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
templateUrl: './app.component.html', templateUrl: './app.component.html',
...@@ -9,11 +11,19 @@ import {Router} from "@angular/router"; ...@@ -9,11 +11,19 @@ import {Router} from "@angular/router";
export class AppComponent { export class AppComponent {
constructor(private router : Router) { constructor(private router : Router, private zone : NgZone) {
(<any>window).router = router;
window.angularRoute = (url => {
zone.run(() => {
router.navigateByUrl(url);
});
});
} }
title = 'app works!'; title = 'app works!';
} }
...@@ -13,7 +13,7 @@ import {TestComponent} from "./test/test.component"; ...@@ -13,7 +13,7 @@ import {TestComponent} from "./test/test.component";
const appRoutes: Routes = [ const appRoutes: Routes = [
{ path: 'viplist', component: ViplistComponent }, { path: 'vip/viplist', component: ViplistComponent },
{ path: 'test', component: TestComponent } { path: 'test', component: TestComponent }
]; ];
......
...@@ -17,7 +17,6 @@ export class MoyaRestModule { ...@@ -17,7 +17,6 @@ export class MoyaRestModule {
static forRoot(): ModuleWithProviders { static forRoot(): ModuleWithProviders {
return { return {
ngModule: MoyaRestModule, ngModule: MoyaRestModule,
providers: [ providers: [
MoyaRestService, MoyaRestService,
......
...@@ -47,6 +47,20 @@ export class ViplistService { ...@@ -47,6 +47,20 @@ export class ViplistService {
} }
public deleteProm(vip: Vip): Promise<boolean> {
if (!vip.id)
throw new Error("TODO: errori, tyhmä vippi");
return this.moyaRestService.delete("v2/vip/" + vip.id)
.first()
.toPromise()
.then(r => r.ok);
}
public getWithId(id: number): Observable<Vip> { public getWithId(id: number): Observable<Vip> {
return this.moyaRestService.get("v2/vip/" + id) return this.moyaRestService.get("v2/vip/" + id)
.map(v => v.json()); .map(v => v.json());
......
console.log("foo");
...@@ -442,7 +442,11 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -442,7 +442,11 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE account_events DROP COLUMN delivered_count;" "ALTER TABLE account_events DROP COLUMN delivered_count;"
}); });
} dbUpdates.add(new String[] {
"ALTER TABLE menuitem ADD COLUMN angularpage BOOLEAN NOT NULL DEFAULT false;"
});
}
public BootstrapBean() { public BootstrapBean() {
} }
......
...@@ -113,6 +113,7 @@ public class MenuBean implements MenuBeanLocal { ...@@ -113,6 +113,7 @@ public class MenuBean implements MenuBeanLocal {
usermenu.addPage(menuitemfacade.findOrCreate("/frontpage"), UserPermission.ANYUSER); usermenu.addPage(menuitemfacade.findOrCreate("/frontpage"), UserPermission.ANYUSER);
usermenu.addPage(menuitemfacade.findOrCreate("/checkout/return"), null).setVisible(false); usermenu.addPage(menuitemfacade.findOrCreate("/checkout/return"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/checkout/delayed"), null).setVisible(false); usermenu.addPage(menuitemfacade.findOrCreate("/checkout/delayed"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/checkout/reject"), null).setVisible(false); usermenu.addPage(menuitemfacade.findOrCreate("/checkout/reject"), null).setVisible(false);
usermenu.addPage(menuitemfacade.findOrCreate("/checkout/cancel"), null).setVisible(false); usermenu.addPage(menuitemfacade.findOrCreate("/checkout/cancel"), null).setVisible(false);
...@@ -139,6 +140,9 @@ public class MenuBean implements MenuBeanLocal { ...@@ -139,6 +140,9 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation helpmenu = usermenu.addPage(null, null); MenuNavigation helpmenu = usermenu.addPage(null, null);
helpmenu.setKey("topnavi.help"); helpmenu.setKey("topnavi.help");
helpmenu.addPage(menuitemfacade.findOrCreate("/help"), UserPermission.HELPPAGE); helpmenu.addPage(menuitemfacade.findOrCreate("/help"), UserPermission.HELPPAGE);
helpmenu.addPage(menuitemfacade.findOrCreate("/angular", true), null). setVisible(false);
MenuNavigation userkauppa = usermenu.addPage(null, null); MenuNavigation userkauppa = usermenu.addPage(null, null);
userkauppa.setKey("topnavi.usershop"); userkauppa.setKey("topnavi.usershop");
...@@ -260,6 +264,7 @@ public class MenuBean implements MenuBeanLocal { ...@@ -260,6 +264,7 @@ public class MenuBean implements MenuBeanLocal {
vips.addPage(menuitemfacade.findOrCreate("/vip/multiadd"), VipPermission.EDIT); vips.addPage(menuitemfacade.findOrCreate("/vip/multiadd"), VipPermission.EDIT);
vips.addPage(menuitemfacade.findOrCreate("/vip/deliver"), VipPermission.VIEW).setVisible(false); vips.addPage(menuitemfacade.findOrCreate("/vip/deliver"), VipPermission.VIEW).setVisible(false);
vips.addPage(menuitemfacade.findOrCreate("/vip/edit"), VipPermission.VIEW).setVisible(false); vips.addPage(menuitemfacade.findOrCreate("/vip/edit"), VipPermission.VIEW).setVisible(false);
adminuser.addPage(menuitemfacade.findOrCreate("/angular/vip/viplist", true), null);
MenuNavigation adminAssociation = adminmenu.addPage(null, null); MenuNavigation adminAssociation = adminmenu.addPage(null, null);
adminAssociation.setKey("topnavi.adminassoc"); adminAssociation.setKey("topnavi.adminassoc");
......
...@@ -41,7 +41,12 @@ public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> { ...@@ -41,7 +41,12 @@ public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> {
super(Menuitem.class); super(Menuitem.class);
} }
public Menuitem findOrCreate(String url) { public Menuitem findOrCreate(String url) {
return findOrCreate(url, false);
}
public Menuitem findOrCreate(String url, boolean angularPage) {
if (url == null || url.isEmpty()) { if (url == null || url.isEmpty()) {
return null; return null;
} }
...@@ -56,6 +61,7 @@ public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> { ...@@ -56,6 +61,7 @@ public class MenuitemFacade extends IntegerPkGenericFacade<Menuitem> {
if (ret == null) { if (ret == null) {
ret = new Menuitem(); ret = new Menuitem();
ret.setUrl(url); ret.setUrl(url);
ret.setAngularPage(angularPage);
create(ret); create(ret);
} }
return ret; return ret;
......
...@@ -38,6 +38,9 @@ public class Menuitem extends GenericEntity { ...@@ -38,6 +38,9 @@ public class Menuitem extends GenericEntity {
@Column(nullable = false, unique = true) @Column(nullable = false, unique = true)
private String url; private String url;
@Column(nullable = false, name = "angularpage")
private boolean angularPage = false;
@Lob @Lob
private String description; private String description;
...@@ -69,4 +72,11 @@ public class Menuitem extends GenericEntity { ...@@ -69,4 +72,11 @@ public class Menuitem extends GenericEntity {
this.navigations = navigations; this.navigations = navigations;
} }
public boolean isAngularPage() {
return angularPage;
}
public void setAngularPage(boolean angularPage) {
this.angularPage = angularPage;
}
} }
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces
http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd"> http://ocpsoft.org/xml/ns/prettyfaces/rewrite-config-prettyfaces.xsd">
<rewrite match="^/angular/.*" substitute="/angular.jsf" redirect="chain" /> <rewrite match="^(/angular/.*)$" substitute="/angular.jsf?pagename=$1" redirect="chain" />
</pretty-config> </pretty-config>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
>
<h:head> <h:head>
<title></title> <title></title>
</h:head> </h:head>
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="pagename" value="#{angularPageName.pagename}" />
<f:event type="preRenderView" listener="#{angularPageName.init()}" />
</f:metadata>
<ui:define name="headerdata"> <ui:define name="headerdata">
<!-- base href="/MoyaWeb/resources/angular-dist/"></base--> <!-- base href="/MoyaWeb/resources/angular-dist/"></base-->
<base href="/MoyaWeb/angular/"></base> <base href="/MoyaWeb/angular/"></base>
</ui:define> </ui:define>
<ui:define name="content"> <ui:define name="content">
<h:form>
<p:remoteCommand name="pageNameSetter" actionListener="#{angularPageName.pagenameRemoteCommand}" update=":mainMenu:panelmenu" />
</h:form>
<link rel="stylesheet" href="/MoyaWeb/resources/angular-dist/styles.bundle.css" /> <link rel="stylesheet" href="/MoyaWeb/resources/angular-dist/styles.bundle.css" />
<app-root>Lattaillaans</app-root> <app-root>Lattaillaans</app-root>
...@@ -18,8 +32,6 @@ ...@@ -18,8 +32,6 @@
<script type="text/javascript" src="/MoyaWeb/resources/angular-dist/vendor.bundle.js"></script> <script type="text/javascript" src="/MoyaWeb/resources/angular-dist/vendor.bundle.js"></script>
<script type="text/javascript" src="/MoyaWeb/resources/angular-dist/main.bundle.js"></script> <script type="text/javascript" src="/MoyaWeb/resources/angular-dist/main.bundle.js"></script>
</ui:define> </ui:define>
</ui:composition> </ui:composition>
......
$(document).ready(function() { $(document).ready(function () {
if (PrimeFaces.getCookie("moyaLeftMenu") != null) { if (PrimeFaces.getCookie("moyaLeftMenu") != null) {
var menuToExpand = PrimeFaces.getCookie("moyaLeftMenu").split(","); var menuToExpand = PrimeFaces.getCookie("moyaLeftMenu").split(",");
for (i = 0; i < menuToExpand.length; ++i) { for (i = 0; i < menuToExpand.length; ++i) {
$("#" + menuToExpand[i]).css("display", "block"); $("#" + menuToExpand[i]).css("display", "block");
} }
} }
}); });
\ No newline at end of file
/**
* One might wonder why this is there.
*
* It would be really nice just link to the angular -page, but there is this "nice" prettyfaces -rewriter
* and it does somehow catch my menulinks, and rewrite them to the .jsf -file, what is JUST what we need. PRKL!
*
* So let's make it the hard and dirty way.
*/
var angularMenuNavigation = function (url) {
if (window.angularRoute) {
var ngUrl = url.substring(8);
window.angularRoute(ngUrl);
pageNameSetter(url);
} else {
window.location.href = window.CONTEXTPATH + url;
}
};
\ No newline at end of file
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
<script type="text/javascript"> <script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
$(function(){ $(function(){
$(window).resize(function() { $(window).resize(function() {
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/blipview/css/general.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/blipview/css/general.css" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/custom_components.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/custom_components.css" />
<ui:insert name="headerdata" /> <ui:insert name="headerdata" />
<script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
</script>
</h:head> </h:head>
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<h:body> <h:body>
<!-- Javascript-lokalisaatiolippupuljausta --> <!-- Javascript-lokalisaatiolippupuljausta -->
<script type="text/javascript"> <script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
$(document) $(document)
.ready( .ready(
function() { function() {
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/custom_components.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/custom_components.css" />
<ui:insert name="headerdata" /> <ui:insert name="headerdata" />
<script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
</script>
</h:head> </h:head>
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
</title> </title>
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/insomnia1/style.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/insomnia1/style.css" />
<ui:insert name="headerdata" /> <ui:insert name="headerdata" />
<script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
</script>
</h:head> </h:head>
<h:body > <h:body >
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/insomnia2/css/general.css" /> <link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/insomnia2/css/general.css" />
<ui:insert name="headerdata" /> <ui:insert name="headerdata" />
<h:outputScript name="prime_calendar.js" library="script" /> <h:outputScript name="prime_calendar.js" library="script" />
<script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
</script>
</h:head> </h:head>
<h:body> <h:body>
<div id="header"> <div id="header">
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
<ui:insert name="headerdata" /> <ui:insert name="headerdata" />
<script language="javascript" type="text/javascript" src="#{request.contextPath}/resources/templates/moyav2/js/main.js"></script> <script language="javascript" type="text/javascript" src="#{request.contextPath}/resources/templates/moyav2/js/main.js"></script>
<script type="text/javascript"> <script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
$(document).ready(function() { $(document).ready(function() {
<ui:repeat value="#{localeSelectorView.availableLocales}" var="loc" varStatus="idx"> <ui:repeat value="#{localeSelectorView.availableLocales}" var="loc" varStatus="idx">
$( $(
......
...@@ -57,6 +57,9 @@ ...@@ -57,6 +57,9 @@
</p:dialog> </p:dialog>
<script type="text/javascript"> <script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
$(document) $(document)
.ready( .ready(
function() { function() {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
<h:body> <h:body>
<!-- Javascript-lokalisaatiolippupuljausta --> <!-- Javascript-lokalisaatiolippupuljausta -->
<script type="text/javascript"> <script type="text/javascript">
window.CONTEXTPATH = "#{request.contextPath}";
$(document) $(document)
.ready( .ready(
function() { function() {
......
...@@ -287,7 +287,13 @@ public class PrimeMenuView extends GenericCDIView { ...@@ -287,7 +287,13 @@ public class PrimeMenuView extends GenericCDIView {
item.setValue(key); item.setValue(key);
item.setOutcome(outcome);
if(m.getItem().isAngularPage()) {
// item.setHref(outcome);
item.setOnclick("angularMenuNavigation('" + outcome +"');");
} else {
item.setOutcome(outcome);
}
} }
return item; return item;
} }
......
package fi.codecrew.moya.web.helper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import javax.enterprise.context.ConversationScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import java.io.Serializable;
import java.util.Map;
/**
*
* Class to store current page when we are on angular -pages.
*
* Created by tuukka on 12/02/17.
*/
@Named
@ConversationScoped
public class AngularPageName extends GenericCDIView {
private static final long serialVersionUID = 1L;
private String pagename;
public void init() {
if(pagename == null) {
super.beginConversation();
}
}
public String getPagename() {
init();
return pagename;
}
public void setPagename(String pagename) {
init();
this.pagename = pagename;
}
public void pagenameRemoteCommand() {
init();
setPagename(((Map<String, String>)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()).get("pagename"));
}
}
...@@ -61,6 +61,10 @@ public class LayoutView implements Serializable { ...@@ -61,6 +61,10 @@ public class LayoutView implements Serializable {
private transient PermissionBeanLocal permbean; private transient PermissionBeanLocal permbean;
@Inject @Inject
private SessionStore sessionStore; private SessionStore sessionStore;
@Inject
private AngularPageName angularPageName;
@EJB @EJB
private transient MenuBeanLocal menubean; private transient MenuBeanLocal menubean;
...@@ -96,11 +100,15 @@ public class LayoutView implements Serializable { ...@@ -96,11 +100,15 @@ public class LayoutView implements Serializable {
{ {
selectedSet = new HashSet<>(); selectedSet = new HashSet<>();
selectedTop = menubean.findNavigation(getPagepath()); selectedTop = menubean.findNavigation(getPagepath());
if(selectedTop != null && selectedTop.getItem().isAngularPage() && angularPageName.getPagename() != null) {
selectedTop = menubean.findNavigation(angularPageName.getPagename());
}
if (selectedTop == null) if (selectedTop == null)
return null; return null;
while (selectedTop.getParent() != null) { while (selectedTop.getParent() != null) {
// logger.debug("Traversing to top {}, key {}", selectedTop, selectedTop.getKey());
selectedSet.add(selectedTop); selectedSet.add(selectedTop);
selectedTop = selectedTop.getParent(); selectedTop = selectedTop.getParent();
} }
...@@ -117,6 +125,7 @@ public class LayoutView implements Serializable { ...@@ -117,6 +125,7 @@ public class LayoutView implements Serializable {
} }
public String getPagepath() { public String getPagepath() {
FacesContext context = FacesContext.getCurrentInstance(); FacesContext context = FacesContext.getCurrentInstance();
if (pagename == null && if (pagename == null &&
context != null && context != null &&
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!