How to localize / internationalize baSidebar of Blur Admin - javascript

i'am trying to localize the baSidebar Navigation of Akveos BlurAdmin.
In the ba-sidebar.html i'am using the translate-filter like {{ ::item.title | translate }}
and the state ist set like:
function routeConfig($stateProvider, dashboardProvider) {
$stateProvider
.state('stateName', {
url: '/stateName',
templateUrl: 'app/pages/[...],
controller: 'stateNameCtrl',
title: 'TITLES.STATENAME',
sidebarMeta: {
order: 200,
},
}) [...]
Angular gets the translation of TITLES.STATENAME from a .json-file. The title of the contentTop is perfectly changing by changing the active language. (i'm using $state.reload(); by ng-click). But the sidebar wont reload. The title still be in the same language which was active while loading the page. If i log off and log in again, the new language is active and shown correctly.
Is there a way to reload the ba-sidebar.html within an ng-click-event like i did with $state.reload()? (i dont want to reload the entire page, because then the site reloads all defaults including the default language)

I solved the problem by saving the language in cookies and reloading the entire page. on load it gets the language from the cookies. if this languagekey isn't set, it loads the default language.
For people who get stuck in the same issue: here is a documentation of using cookies in javascript: http://www.w3schools.com/js/js_cookies.asp

Related

SAPUI5 routing reset after browser refresh

I have developed a SAPUI5 master detail app. When I'm clicking on a master item, the corresponding detail page is shown (so far so good). The problem now is, that if I hit refresh (F5) in the browser, the last selected item is loaded (because of the URL parameter).
What I want to achieve is, to display the master list, but no item is selected. Instead a "select an item" page should be shown instead of the item detail page.
I've tried many things such as manipulate the routing, but none of this works. Any ideas on how to achieve this?
By doing that you give up the whole idea of deep-linking which is imho one of the major benefits of the routing. So think twice before doing so.
Anyways you could just reset the hash before initializing the router in your Component like this:
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/core/routing/HashChanger"
], function (UIComponent, HashChanger) {
"use strict";
return UIComponent.extend("sap.ui.demo.nav.Component", {
metadata: {
manifest: "json"
},
init: function () {
// reset the routing hash
HashChanger.getInstance().replaceHash("");
// call the init function of the parent
UIComponent.prototype.init.apply(this, arguments);
// create the views based on the url/hash
this.getRouter().initialize();
}
});
});
BR
Chris

Angular ui-router not loading external content on state change

I have started building a website using Angular, and have started to use ui-router along with ngAnimation for some sick animations! All was going well until I started adding external resources such as Facebook's Page Widget (https://developers.facebook.com/docs/plugins/page-plugin) and Google Maps API for some custom map styles.
The Issue
I have the Facebook widget on the home page, and it loads fine when you first access the URL as can be seen below (Have to block the name of client, totally not just bad design...):
Once I click on another page to load it in (using ui-view to dynamically bring in a view), for example contact view and go back to the home page (where the code is to display the widget), the widget will no longer load but will load the basic header tag that Facebook provide as can be seen below:
This also happens on the contact page when loading in Google Maps API. If I click on the contact page, there will just be a large white area on where the map should be, but if you had to actually refresh the page the map will load.
I am assuming that the issue is that the website is not able to send a request to either Facebook or Google when a view is loaded in, but can only happen when the page is actually refreshed or a new page load.
My Code
Okay so I'll explain the basics of how my application works along with code. I am rather new with Angular so if I have terrible code, please let me know.
Structure
This is a screen shot of my web apps structure. The main template file is index.html, and any view are within the views directory, which are loaded in using ui-router.
Main Angular applications code (app.js)
var app = angular.module('bmApp', ['ngAnimate', 'ui.router', 'ui.bootstrap'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('header', {
templateUrl: './assets/views/template.html',
})
.state('header.home', {
url: '/',
templateUrl: './assets/views/home.html',
controller: "HomeController"
})
.state('header.about', {
url: '/about',
templateUrl: './assets/views/about.html',
controller: "AboutController"
})
.state('header.work', {
url: '/work',
templateUrl: './assets/views/work.html',
controller: "WorkController"
})
.state('header.services', {
url: '/services',
templateUrl: './assets/views/services.html',
controller: "ServicesController"
})
.state('header.contact', {
url: '/contact',
templateUrl: './assets/views/contact.html',
controller: "ContactController"
});
$urlRouterProvider.otherwise('/'); //if no views are matched, just redirect back to home page.
})
I am using nested views to keep the header of the website static (not changing) and then loading in views under the header, with ngAnimate to make it look cool.
In my main template, index.html, I have a simple <div ui-view></div> to load in the view that is requested. I also have the required script to request Facebook's API just after the . My controllers do not actually currently have anything in them. I did have some vanilla JavaScript in some, but do not currently need it anymore. I also tried to wrap the code provided by Facebook in a function, and call it within the controller for the specific view but that just had the same results of having it within the body on the template (index.html) page.
Pulling my hair out at this, can't seem to find a solution. I hope I have explained my issue without missing out on anything. I appreciate any help you could give, would be so awesome.
Edit: I should have probably mentioned that my main template is index.html, I then inject the view in to /views/template.html AND THEN inject it into index.html. Not too sure if this is best practice, but felt like it would work well (I don't think that is the issue).
I will give you only half of an answer, but maybe it will point you to right direction. I also struggled with Google API in SPA application once. I had the same issue - after entering the contact page, a white box appeared instead of map. The solution turned out to be simple - I just needed to force map reload, when I entered contact sheet. This function was attached as onclick event to contact page link:
function reloadGoogleMap() {
if (counter == 0) {
document.getElementById('google-map').src += '';
counter++;
}
}
I used the counter to make sure it happens only once - you won't need it probably. With Angular, you might need to make sure the reload happens after element is rendered. Maybe a simple directive would work, however I didn't test that:
angular.module('your_directives_module')
.directive('mapLoaded', [mapLoadedDirective]);
function mapLoadedDirective() {
return {
restrict: 'A',
link: function (scope, elem, attrs) {
elem.on('load', function (event) {
// Force reload
elem.src += '';
});
}
};
}
It could be used like:
<!-- Div/iframe with google map -->
<div map-loaded></div>
Maybe Facebook API also has some simple way which you could use to force widget reload when the partial view is loaded, however I've never tried to use that with Angular.
Don't you have to wrap it in a $rootScope.$apply function in order to update your view?
$rootScope.$apply(function () {
// some code
});

Cannot set initial url for main-view

For the app I'm making, when the user first enters the app, the default home page is loaded (let's call it index.html). After the user signs in, they are routed to another page of the app (let's call this feed.html).
When the user leaves the app and decides to come back later, but is still logged into the app, I want the user to automatically see feed.html when the app loads, rather than index.html.
Is there any way I can do this? I have tried changing the default url dynamically and in the html as indicated here, but index.html keeps loading instead of feed.html.
Thanks in advance.
UPDATE:
var mainView;
if (localStorage.getItem("isLoggedIn") !== null){
// If already logged in
mainView = myApp.addView(".view-main", {
url: "feed.html"
});
}
else {
mainView = myApp.addView(".view-main", {});
}
So this is my code. According to the documentation, setting the url parameter when instantiating the main view should set the default url of the page to load when the view loads, but feed.html doesn't load.
Before this, I would forward the user to feed.html after index.html loads using the router:
mainView.router.load({
url: "feed.html"
});
but I would rather have the user land on feed.html instead of index.html if possible.
I have use previous version of framework7. its solve the problem

AngularJS $stateParams when using reloadOnSearch:false

I have a page in my application which uses a search so i have added the "realoadOnSearch:false" which works perfectly
The problem I have is when navigating to the same state with a different stateParam:
when I navigate to #/category/20/ from any other page it works fine... i then have a link on that page to #/category/3 (the parent category for 20) and the URL updates, however the content does not (no console errors)
app.js (main application)
.state('category', {
url: '/category/:categoryId/',
templateUrl: '/Home/Category',
controller: 'categoryCtrl',
reloadOnSearch: false
})
I have tried adding target="_self" to force page reload and it does not work
I have also tried to watch $stateParams for changes and there is nothing
Clicking the link to #/category/3 from #/category/20 (and vice versa) should navigate to the new page and reload the data, where search should NOT reload the page (latter works but not the former)
The URL is prefered to be a ng-href rather than ng-click as it is managed by the root controller
EDIT:
I did not find a direct solution, however i just disabled the reloadOnSearch and my sorting buttons still work so this works for me for now as a solution.
The problem is that reloadOnSearch doesn't do what you think it does; it's actually more like reloadOnStateParams. Setting it to false prevents you from making state changes where only the stateParams change, which is what you're doing here (going from #/category/3 to #/category/20).
You can see this documented on the UI router issues page: https://github.com/angular-ui/ui-router/issues/1079
There's some workarounds in there but none of them are great. You are probably best off using an ng-click that forces a reload manually, something like this:
$state.transitionTo($state.current, $stateParams, {
reload: true,
inherit: false,
notify: true
});

How to change URL path when paging using ajax + jQuery

I am using ajax post requests for doing paging on a feed in my site. When getting the post request data I am reforming the page by clearing previous data and rendering the new data that came from the request. I want to be able to change the URL as well so saving the new page link will get the user to the current page.
Example:
User on page example.com/feed - seeing content of page #1
User clicking to get to page #2 -> ajax post is send and data on the page is changed using js (no refresh)
URL is still example.com/feed but the content is of example.com/feed?page=2
How can I set the URL to point to the new page without triggering a refresh (no redirect) ?
I am using Nodejs + express.
I understand you are aiming at a single page application.
While keeping the url is nice, note you might want distinct urls for directly accessing different parts of your application. Still, you can load content with AJAX and keep a smooth application. The way to go is using the hash part of the location.
The Sammy.js framework gives you a nice base to build upon, you can try it out.
You can use history pushstate but some browsers does not support.
history.pushState({id: 'SOME ID'}, '', 'myurl.html');
And don't forget about window.onpopstate, it pops if user clicks back button.
Redirect the user to an anchor point.
Page 2
And in your document.ready:
if (window.location.hash.length > 1){
var pageNumber = window.location.hash.substring(1);
loadPage(parseInt(pageNumber));
} else{
loadPage(0);
}
I don't believe it is possible to change the query part of the URL without triggering a refresh (probably due to security issues). However you may change the anchor and use an event listener to detect when the anchor is being changed.
//Listener
$(window).on('hashchange', function() {
if(loaction.hash.length > 1) {
//The anchor has been changed.
loadPageWithAjax("example.com/feed.php?page=" + location.hash.substring(1));
} else {
//Load standard page
...
}
});
Change the anchor to load new feed
Page 2
Remember to not use an anchor that is used as an id, since this makes the browser scroll to that element.

Categories

Resources