How to Show 1 element and hide multiple elements in Angular 7 - angular7

I am trying to click a details about an element and I just want the details of that particular details to show and hide other element details.
“This is Angular 7. I’ve tried on using *ngIf and failed in it. I am using parent and child component communication technique.
Parent HTML
<h4>2 Days Bangalore Mysore</h4>
</div>
<div class="ft-foot">
<h4 class="ft-title text-upper"><a routerLink="/details"
(click)="detailsbm2d()" class="btn btn-primary">DETAILS</a></h4>
</div>
<h4>2 Days Kodaikanal</h4><br>
</div>
<div class="ft-foot">
<h4 class="ft-title text-upper"><a routerLink="/details"
(click)="detailskod2d()" class="btn btn-primary">DETAILS</a></h4>
</div>
<h4>2 Days Ooty</h4><br>
</div>
<div class="ft-foot">
<h4 class="ft-title text-upper"><a routerLink="/details"
(click)="detailsoo2d()" class="btn btn-primary">DETAILS</a></h4>
</div>
Parent component
show: boolean= true;
show1:any = true;
show2: boolean = true;
detailsbm2d() {
this.show = !this.show;
}
detailskod2d() {
this.show1 = !this.show1;
}
}
detailsoo2d() {
this.show2 = !this.show2;
}
ngOnInit() {
}
}
Child HTML
<div class="container">
<div class="row">
<section class="col-sm-6">
<h1 class="text-upper">TOUR PLAN</h1>
</section>
</div>
</div>
<div class="container" *ngIf="!show">
<div id="page" class="col-md-8">
<P> Element1 </p>
</div>
</div>
<div class="container" *ngIf="!show1">
<div id="page" class="col-md-8">
<P> Element2 </p>
</div>
</div>
<div class="main-contents" *ngIf="!show2">
<div id="page" class="col-md-8">
<P> Element3 </p>
</div>
</div>
Child component
export class {
#Input() show1: boolean;
#Input() show2: boolean;
#Input() public text: string;
constructor() { }
ngOnInit() {
}
}
I expect only the Element1 to be displayed when I click the DETAILS button, but I get all the Element1,Element2 and Element3 are getting displayed.

show: boolean= false ;
show1:any = false ;
show2: boolean = false ;
// making show; show1; show2 initially to false hides it. when you click the DETAILS
// button the click event shows it.
and convert all *ngIf = show // (i.e., remove "!" from all *ngIf's)

correction of #muzzu47's answer
Parent component
show: boolean= true; //Default True for initially show first content
show1:any = false ;
show2: boolean = false ;
detailsbm2d() {
this.show = !this.show;
this.show2 = false;
this.show1 = false;
}
detailskod2d() {
this.show = false;
this.show2 = false;
this.show1 = !this.show1;
}
detailsoo2d() {
this.show = false;
this.show1 = false;
this.show2 = !this.show2;
}
In function other element should be false because you want to display at a time single element
convert all *ngIf = show // (i.e., remove "!" from all *ngIf's)

Related

mat checkbox not clearing when cancel form button clicked

I have a list of cities in a form with check box. when trying cancel form , the list of checkboxes checked are not clearing . but when i uncheck each of the checkbox, it works
api-model.ts
export interface City{
city_Name: string;
}
class-model.ts
export class eModel {
cityList: Array<City>=[];
}
app.html
<div class="row">
<div class="column-3">
<div *ngFor="let data of cityData; let i=index">
<mat-checkbox color="primary" (change)="getCheckboxValues(data, i, $event)" >
{{data.city_Name}}
</mat-checkbox>
</div>
</div>
</div>
<button mat-raised-button class="cancel-button" (click)="Cancel()">Cancel</button>
app.ts
cityData: City[] = [];
ngOnInit(): void {
this.eModel.cityList = [];
loadCityList();
}
loadCityList() {
return this._getAPIservice.getCity().subscribe(data => {
this.cityData = data;
});
}
Cancel(): void {
this.eForm.resetForm({});
loadCityList();
this.eModel.cityList = [];
}
This can be achieved by using element reference variable.
Try this:
<div class="row">
<div class="column-3">
<div *ngFor="let data of cityData; let i=index">
<mat-checkbox #chkboxes color="primary" (change)="getCheckboxValues(data, i, $event)" >
{{data.city_Name}}
</mat-checkbox>
</div>
</div>
</div>
<button mat-raised-button class="cancel-button" (click)="Cancel()">Cancel</button>
In ts:
#ViewChildren('chkboxes') chkboxes: QueryList<any>; // Define this at the top
Cancel(){
this.chkboxes.forEach(x => x.checked = false);
}

View Component Loading Issue on Production ASP.NET Core

I am working on an application where I want to load View Component. On local machine it is working with out any problem or error but when I make deployment it is not working properly and gives me error of 500. Here is my implementation.
Jquery Function
function UPdateHistoryGrid() {
$("#notification-history").empty();
var _url = '#Url.Action("NotificationHistory", "Notification")';
$.ajax({
type: "GET",
url: _url,
success: function (result) {
$("#notification-history").html(result);
},
error(res) {
console.log(res)
}
});
};
Controller action method
public IActionResult NotificationHistory()
{
return ViewComponent("NotificationHistory");
}
View Component .cs
public class NotificationHistoryViewComponent : ViewComponent
{
protected readonly IHttpNetClientService _apiService;
IUserProfileInfoProvider _userInfoProvider;
public NotificationHistoryViewComponent(IHttpNetClientService HttpService,
IUserProfileInfoProvider userInfo)
{
_apiService = HttpService;
_userInfoProvider = userInfo;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = new NotificationParentModel();
var NotificationApiJsonResult = await _apiService.GetAllAsync(Notification_API_URL.GetAllNotificationsHistory.GetEnumDescription(), _userInfoProvider.GetUserInfo().Id, _userInfoProvider.GetToken());
var notificationData = JsonConvert.DeserializeObject<ResponseDTO<IEnumerable<GMDNotificationDTO>>>(NotificationApiJsonResult);
model.NotificaitonList = notificationData.Data.ToList();
return await Task.FromResult((IViewComponentResult)View("NotificationHistory", model));
}
}
View Code
#using GMDSuperAdmin.Helper
#model GMDSuperAdmin.Models.NotificationParentModel
<div class="notificationCard-Container text-container #(!Model.IsToday ? "mt-5" : "") bg-white px-0">
<div class="position-relative">
<h5 class="text-center py-3">Notification History</h5>
</div>
#{
if (Model.NotificaitonList.Count() > 0)
{
foreach (var item in Model.NotificaitonList)
{
<div class="row message-row message-row-2 mx-0 py-1" id="clickable-row">
<div class="row mx-0 main-notificationRow justify-content-between" id="translate-row" #*onclick="selectedNotification(this, #item.NOtificationId)"*#>
<div class="d-flex align-items-center py-2">
<div class="notification-list_img document-noti mx-2 mt-1 mx-lg-3">
<i class="fas fa-file-alt"></i>
</div>
<div class="notifierInfo">
<p class="message-paragraph mb-0">
#item.NotificationDescription
</p>
</div>
</div>
<div class="notification-time pt-1 pb-2 mx-2">
<p class="message-paragraph text-right mb-0">
#(DateTimeHelper.TimeAgo(item.CreatedDate))
</p>
</div>
</div>
</div>
}
}
else
{
<div class="row message-row py-1 mx-0" id="clickable-row">
<div class="row mx-0 main-notificationRow" id="translate-row">
<div class="col-12 col-lg-12">
<p class="message-paragraph text-muted mb-0 text-center">
<b>No Notification Found!</b>
</p>
</div>
</div>
</div>
}
}
</div>
Please rename your view component as default. NotificatioHistory.cshtml to Default.cshtml. Some time it makes issues with custom names on production so the recommended way is to use Default.cshtml.
public class NotificationHistoryViewComponent : ViewComponent
{
protected readonly IHttpNetClientService _apiService;
IUserProfileInfoProvider _userInfoProvider;
public NotificationHistoryViewComponent(IHttpNetClientService HttpService,
IUserProfileInfoProvider userInfo)
{
_apiService = HttpService;
_userInfoProvider = userInfo;
}
public async Task<IViewComponentResult> InvokeAsync()
{
var model = new NotificationParentModel();
var NotificationApiJsonResult = await _apiService.GetAllAsync(Notification_API_URL.GetAllNotificationsHistory.GetEnumDescription(),
_userInfoProvider.GetUserInfo().Id, _userInfoProvider.GetToken());
var notificationData = JsonConvert.DeserializeObject<ResponseDTO<IEnumerable<GMDNotificationDTO>>>(NotificationApiJsonResult);
model.NotificaitonList = notificationData.Data.ToList();
return View(model); //// Change this ...
}
}

Parameter in a controller function returns undefined ReferenceError

I'm going through this learning lab for AngularJS. I can get the example to work as-is (with a minor bug fix).
I'm also trying to learn some good coding practices concerning AngluarJS by referencing this guide. This has resulted in a js file that looks like this:
(function () {
'use strict';
angular.module('QuizApp', []);
angular.module('QuizApp').controller('QuizCtrl', QuizController);
function QuizController($http) {
var vm = this;
vm.answer = answer();
vm.answered = false;
vm.correctAnswer = false;
vm.nextQuestion = nextQuestion();
vm.options = [];
vm.sendAnswer = sendAnswer(option);
vm.title = "loading question...";
vm.working = false;
function answer() {
return vm.correctAnswer ? 'correct' : 'incorrect';
}
function nextQuestion() {
vm.working = true;
vm.answered = false;
vm.title = "loading question...";
vm.options = [];
$http.get("/api/trivia")
.success(function (data, status, headers, config) {
vm.options = data.options;
vm.title = data.title;
vm.answered = false;
vm.working = false;
}).error(function (data, status, headers, config) {
vm.title = "Oops... something went wrong.";
vm.working = false;
});
}
function sendAnswer(option) {
vm.working = true;
vm.answered = true;
$http.post('/api/trivia', { 'questionId': option.questionId, 'optionId': option.id })
.success(function (data, status, headers, config) {
vm.correctAnswer = (data === true);
vm.working = false;
})
.error(function (data, status, headers, config) {
vm.title = "Oops... something went wrong.";
vm.working = false;
});
}
};
})();
However, this code is throwing the following error when the page loads.
ReferenceError: 'option' is undefined
at QuizController (http://localhost:17640/Scripts/app/quiz-controller.js:16:9)
at invoke (http://localhost:17640/Scripts/angular.js:4473:7)
at Anonymous function (http://localhost:17640/Scripts/angular.js:9093:11)
at nodeLinkFn (http://localhost:17640/Scripts/angular.js:8205:13)
at compositeLinkFn (http://localhost:17640/Scripts/angular.js:7637:13)
at compositeLinkFn (http://localhost:17640/Scripts/angular.js:7641:13)
at compositeLinkFn (http://localhost:17640/Scripts/angular.js:7641:13)
at compositeLinkFn (http://localhost:17640/Scripts/angular.js:7641:13)
at compositeLinkFn (http://localhost:17640/Scripts/angular.js:7641:13)
at publicLinkFn (http://localhost:17640/Scripts/angular.js:7512:30)
For whatever reason, it appears to be attempting to execute sendAnswer immediately. Since it's failing, the javascript halts mid-way displaying the angular property name {{title}} on the page instead of rendering the question on the page. I've tried different ways of defining and calling vm.sendAnswer and function sendAnswer, without any luck.
For reference, here is the code to my view (note the ng-repeat on options - this view code works perfectly when following the lab exercise exactly):
<div id="bodyContainer" ng-app="QuizApp">
<section id="content">
<div class="container">
<div class="row">
<div class="flip-container text-center col-md-12" ng-controller="QuizCtrl" ng-init="nextQuestion()">
<div class="back" ng-class="{flip: answered, correct: correctAnswer, incorrect:!correctAnswer}">
<p class="lead">{{answer()}}</p>
<p>
<button class="btn btn-info btn-lg next option" ng-click="nextQuestion()" ng-disabled="working">Next Question</button>
</p>
</div>
<div class="front" ng-class="{flip: answered}">
<p class="lead">{{title}}</p>
<div class="row text-center">
<button class="btn btn-info btn-lg option" ng-repeat="option in options" ng-click="sendAnswer(option)" ng-disabled="working">{{option.title}}</button>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
How can I preserve my coding practice (essentially, avoid using $scope in this situation and declare all of my viewmodel properties at the top of the controller) yet get the function to operate properly?
Are you planning to send in
vm.options = [];
vm.sendAnswer = sendAnswer(option);
vm.options into the sendAnswer() function because option is not defined. you won't get an error if you enclose 'option' in a string and pass it into the function.But then you wouldn't be getting the object you want.
add this somewhere at the top var option = {}.
I have this example working now.
For starters, the controller properties that are plugged into functions just need to reference the names of the functions.
vm.answer = answer;
vm.nextQuestion = nextQuestion;
vm.sendAnswer = sendAnswer;
Then we need an alias for our controller on our view so we can reference it more easily.
<div class="flip-container text-center col-md-12" ng-controller="QuizCtrl as quiz" ng-init="quiz.nextQuestion()">
<div class="back" ng-class="{flip: quiz.answered, correct: quiz.correctAnswer, incorrect:!quiz.correctAnswer}">
<p class="lead">{{quiz.answer()}}</p>
<p>
<button class="btn btn-info btn-lg next option" ng-click="quiz.nextQuestion()" ng-disabled="quiz.working">Next Question</button>
</p>
</div>
<div class="front" ng-class="{flip: quiz.answered}">
<p class="lead">{{quiz.title}}</p>
<div class="row text-center">
<button class="btn btn-info btn-lg option" ng-repeat="option in quiz.options" ng-click="quiz.sendAnswer(option)" ng-disabled="quiz.working">{{option.title}}</button>
</div>
</div>
</div>
And that's pretty much it. Just clean up the property definitions in the angular controller and then utilize an alias for the controller on the view. Everything else is pretty much the same code as what's in the question.
Here's the complete code now. Angular controller:
(function () {
'use strict';
angular.module('QuizApp', []);
angular.module('QuizApp').controller('QuizCtrl', QuizController);
function QuizController($http) {
var vm = this;
vm.answer = answer;
vm.answered = false;
vm.correctAnswer = false;
vm.nextQuestion = nextQuestion;
vm.options = [];
vm.sendAnswer = sendAnswer;
vm.title = "loading question...";
vm.working = false;
function answer() {
return vm.correctAnswer ? 'correct' : 'incorrect';
};
function nextQuestion() {
vm.working = true;
vm.answered = false;
vm.title = "loading question...";
vm.options = [];
$http.get("/api/trivia")
.success(function (data, status, headers, config) {
var answerOptions = data.options;
while (answerOptions.length > 0){
var random = Math.floor(Math.random() * answerOptions.length, 0);
alert(random);
vm.options.push(answerOptions[random]);
answerOptions.splice(random, 1);
}
//vm.options = data.options;
vm.title = data.title;
vm.answered = false;
vm.working = false;
}).error(function (data, status, headers, config) {
vm.title = "Oops... something went wrong.";
vm.working = false;
});
};
function sendAnswer(option)
{
vm.working = true;
vm.answered = true;
$http.post('/api/trivia', { 'questionId': option.questionId, 'optionId': option.id }).success(function (data, status, headers, config) {
vm.correctAnswer = (data === true);
}).error(function (data, status, headers, config) {
vm.title = "Oops... something went wrong";
});
vm.working = false;
}
};
})();
MVC Index view:
#{
ViewBag.Title = "Play";
}
<div id="bodyContainer" ng-app="QuizApp">
<section id="content">
<div class="container">
<div class="row">
<div class="flip-container text-center col-md-12" ng-controller="QuizCtrl as quiz" ng-init="quiz.nextQuestion()">
<div class="back" ng-class="{flip: quiz.answered, correct: quiz.correctAnswer, incorrect:!quiz.correctAnswer}">
<p class="lead">{{quiz.answer()}}</p>
<p>
<button class="btn btn-info btn-lg next option" ng-click="quiz.nextQuestion()" ng-disabled="quiz.working">Next Question</button>
</p>
</div>
<div class="front" ng-class="{flip: quiz.answered}">
<p class="lead">{{quiz.title}}</p>
<div class="row text-center">
<button class="btn btn-info btn-lg option" ng-repeat="option in quiz.options" ng-click="quiz.sendAnswer(option)" ng-disabled="quiz.working">{{option.title}}</button>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
#section scripts {
#Scripts.Render("~/Scripts/angular.js")
#Scripts.Render("~/Scripts/app/quiz-controller.js")
}

Page flickers when Angular JS is used in Bootstrap modal, but works fine after reload. (tried ngCloak too)

Application Description:
I am making a simple Ecommerce website(single page product listing) using AngularJS and Rails. It only handles Cash On Delivery Orders. The user adds products and checksout. All this process is done in Angular. The cart is stored in localstorage.When he checksout a modal pops up asking him to choose choose between two shipping methods. Depending on the shipping method he chooses the price which is displayed on the bootstrap modal has to be updated.
Problem Description:
The page flickers(the curly braces appear) when I try to do this. When I reload the whole thing it works properly.
After some research I found that I have to use $compile but I am not sure of how to use it. i read several tutorials but I am not able to figure it out.
Here is my angular code. The two functions I used in bootstrap modal are shippingCharges(), totalPrice(). They are at the end of the angular code.
<script>
var products = angular.module('products', []);
products.controller('ListController', ['$scope', function($scope) {
$scope.categories = JSON.parse('<%= j raw(#categories_hash.to_json) %>');
$scope.activeCategory = null;
$scope.cart = JSON.parse(localStorage.getItem('cart'));
if (!!$scope.cart) {
angular.forEach($scope.cart, function(item_quantity, item_id) {
$scope.categories.forEach(function(category, index1) {
category.products.forEach(function(product, index2) {
if (item_id == product.id) {
product.ordered_quantity = item_quantity;
}
});
});
});
};
$scope.formData = {
shipping: "scheduled"
};
$scope.addProductToCart = function(product_id) {
// event.preventDefault();
var cart = $scope.cart;
if (!cart) {
cart = {}
}
if (!cart[product_id]) {
cart[product_id] = 0;
}
cart[product_id] += 1;
localStorage.setItem('cart', JSON.stringify(cart));
$scope.cart = cart;
};
$scope.increaseQuantity = function(product) {
product.ordered_quantity += 1;
$scope.addProductToCart(product.id);
};
$scope.decreaseQuantity = function(product) {
product.ordered_quantity = product.ordered_quantity - 1;
var cart = $scope.cart;
if (!cart) {
cart = {}
}
cart[product.id] -= 1;
localStorage.setItem('cart', JSON.stringify(cart));
$scope.cart = cart;
};
$scope.removeProductFromCart = function(product_id) {
var cart = $scope.cart;
cart[product_id] = 0;
localStorage.setItem('cart', JSON.stringify(cart));
$scope.cart = cart;
}
$scope.totalPrice = function() {
total = 0;
$scope.categories.forEach(function(category, index) {
category.products.forEach(function(product, index1) {
total += product.price*product.ordered_quantity;
});
});
return total;
};
$scope.toggleCategory = function(category) {
if ($scope.activeCategory == category.category_id) {
$scope.activeCategory = null;
} else {
$scope.activeCategory = category.category_id;
}
};
$scope.shouldShowCategory = function(category) {
return($scope.activeCategory == category.category_id);
};
$scope.shippingCharges = function() {
var cart = $scope.cart;
var shippingcost;
if ($scope.formData.shipping == "scheduled"){
shippingcost = 35;
}else if ($scope.formData.shipping == "unscheduled"){
shippingcost = 75;
}
cart["shipping"]=shippingcost;
localStorage.setItem('cart', JSON.stringify(cart));
return shippingcost;
}
}]);
</script>
Boostrap Modal Code
<div class="modal fade" id="checkoutModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" ng-controller="ListController" ng-cloak >
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Information for delivery</h4>
</div>
<div class="modal-body checkout-details">
<form id="checkoutForm" class="form-horizontal">
<div id="checkoutLoading" class="progress progress-striped active hidden">
<div class="progress-bar progress-bar-success" style="width: 100%"></div>
</div>
<fieldset>
<legend>Choose a delivery method</legend>
<p>We are making a schedule delivery to <strong><%= delivery_timing[0] %></strong> on <strong><%= delivery_timing[1] %></strong>. If you are not located in the mentioned places please choose an unscheduled delivery</p>
<div class="radio">
<label><input type="radio" name="shipping" value="scheduled" ng-model="formData.shipping" ng-change="setShipping('scheduled')">Scheduled Delivery(Rs. 35)</label>
</div>
<div class="radio">
<label><input type="radio" name="shipping" value="unscheduled" ng-model="formData.shipping" ng-change="setShipping('unscheduled')">Unscheduled Delivery(Rs.75)</label>
</div>
<p class="ng-cloak">Total: {{shippingCharges() + totalPrice()}}</p>
</fieldset>
<fieldset>
<legend>Please provide delivery details:</legend>
<div class="errorMessage alert alert-dismissible alert-danger hidden">
<strong>Oh snap!</strong> Please provide phone number and address.
</div>
<div id="checkoutEmailFormGroup" class="form-group">
<label for="checkoutPhone">Email</label>
<input type="email" class="form-control" id="checkoutEmail" placeholder="me#example.com" >
</div>
<div id="checkoutPhoneFormGroup" class="form-group">
<label for="checkoutPhone">Phone</label>
<input type="phone" class="form-control" id="checkoutPhone" placeholder="+91-9999-999-999" >
</div>
<div id="checkoutAddressFormGroup" class="form-group">
<label for="checkoutAddress">Address</label>
<textarea class="form-control" id="checkoutAddress" placeholder="Plot No
Street Name
City" rows="5"></textarea>
</div>
</fieldset>
</form>
</div>
<div class="modal-footer">
<p class="ng-cloak" >Total cost: {{shippingCharges() + totalPrice()}}</p>
<button type="button" class="btn btn-default" data-dismiss="modal">Go Back</button>
<button id="checkout_trigger" type="button" class="btn btn-brown">Confirm</button>
</div>
</div>
</div>
</div>
Can you please let me know how to compile the code in the Bootstrap modal?

Highcharts showLoading displaced

When I call the showLoading method of a chart the show loading screen appears but on the wrong position. I am not sure which is causing this. I have created a plunk (http://plnkr.co/edit/FdBqoPJZmopNc4s33Jcg) but I could not reproduce the wrong behaviour with the plunk.
$scope.renderColumnChart = function (date) {
var chart = {};
$.each(Highcharts.charts, function (index, c) {
if (c && c.renderTo.id === "column-chart")
chart = c;
});
$scope.columnChartConfig.series = [];
$scope.columnChartConfig.title.text = moment(date).format("DD.MM.YYYY");
$scope.columnChartUrl = SharedService.createUrl(SharedService.createUrlDataByPeriod($scope.dimension, SharedService.getPeriodFromDate($scope.dimension, date), date, 0, 0, 1, [19]));
chart.showLoading(); //TODO show loading wrong place
$q.all([
ColumnChartService2.getData($scope.columnChartUrl, globalConfig.oDataServer + globalConfig.ageGroups)
]).then(function (result) {
$scope.columnChartConfig.series.push({
name: "Personen pro Altersgruppe",
color: Highcharts.getOptions().colors[0],
data: result[0].data
});
//chart.hideLoading();
});
}
regards
Additional Information
Here is the full code of the angular controller and the html template.
Controller
ManagementReporting.controller("CustomerHeadCountController", ['$rootScope', '$scope', '$q', 'globalConfig', 'SharedService', 'MultiLineChartService', 'ColumnChartService2',
function ($rootScope, $scope, $q, globalConfig, SharedService, MultiLineChartService, ColumnChartService2) {
SharedService.cleanUpCharts();
$scope.title = 'Customer Head Count';
var init = function () {
$scope.dimension = SharedService.getGranularity()[0];
var ranges = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
$scope.before = ranges[3];
$scope.after = ranges[5];
$scope.referenceDate = new Date(moment().subtract("month", 0).format("YYYY-MM-DD"));
$scope.period = SharedService.getPeriods($scope.dimension, $scope.referenceDate).period;
};
init();
// TODO add charts
$scope.refresh = function () {
$scope.processCharts();
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////// EVENTS ////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// when route change!!!!
$scope.$on('$routeChangeSuccess', function () {
$rootScope.$broadcast('change.activeSite', 'Anzahl Kunden auf basis verrechneter Einsätze (jeder Kunde in der Dimension einmalig gezählt)');
$scope.processCharts();
});
$scope.processCharts = function () {
$("#modal-processing-report-data").modal("show");
$scope.lineChartConfig = MultiLineChartService.getConfig();
$scope.lineChartConfig.series = [];
$scope.url = SharedService.createUrl(SharedService.createUrlDataByPeriod($scope.dimension, $scope.period.value, $scope.date, $scope.before, $scope.after, 1, [17]));
$scope.urlRegression = SharedService.createUrl(SharedService.createUrlDataByPeriod($scope.dimension, $scope.period.value, $scope.date, $scope.before, $scope.after, 1, [21]));
$scope.columnChartConfig = ColumnChartService2.getConfig();
$scope.columnChartConfig.series = [];
$q.all([
MultiLineChartService.getData($scope.url),
MultiLineChartService.getRegressionData($scope.urlRegression)
]).then(function(result) {
$scope.lineChartConfig.series = result[0].data;
$scope.lineChartConfig.series.push(result[1].data);
$scope.renderColumnChart($scope.date);
var normal = Enumerable.from(result[0].data).where(function(record) {
return record.name === "Normal";
}).toArray()[0];
$scope.average = parseFloat(normal.avg.toFixed(2));
$scope.minimum = normal.min;
$scope.maximum = normal.max;
$("#modal-processing-report-data").modal("hide");
});
}
$scope.$on('multilinechart.click', function (angularEvent, highchartEvent, point) {
var date = new Date(highchartEvent.point.x);
$scope.renderColumnChart(date);
});
$scope.renderColumnChart = function (date) {
var chart = {};
$.each(Highcharts.charts, function (index, c) {
if (c && c.renderTo.id === "column-chart")
chart = c;
});
$scope.columnChartConfig.series = [];
$scope.columnChartConfig.title.text = moment(date).format("DD.MM.YYYY");
$scope.columnChartUrl = SharedService.createUrl(SharedService.createUrlDataByPeriod($scope.dimension, SharedService.getPeriodFromDate($scope.dimension, date), date, 0, 0, 1, [19]));
//chart.showLoading(); //TODO show loading wrong place
$q.all([
ColumnChartService2.getData($scope.columnChartUrl, globalConfig.oDataServer + globalConfig.ageGroups)
]).then(function (result) {
$scope.columnChartConfig.series.push({
name: "Personen pro Altersgruppe",
color: Highcharts.getOptions().colors[0],
data: result[0].data
});
//chart.hideLoading();
});
}
}]);
HTML Template
<div>
<!--
<div class="row">
<div data-ng-include="selectionHeader.url"></div>
</div>
-->
<div class="dateselector"
data-dimension="dimension"
data-before="before"
data-date="date"
data-period="period"
data-after="after"
data-refresh="refresh()">
</div>
<div class="well">
<highchart id="line-chart"
data-config="lineChartConfig"
data-chart="lineChart" />
<div class="text-center">
<span translate>Minimum: </span> {{minimum}}, <span translate>Maximum: </span> {{maximum}}, <span translate>Durchschnitt: </span> {{average}}
</div>
</div>
<div class="well">
<highchart id="column-chart"
data-config="columnChartConfig"
data-chart="columnChart" />
</div>
<!-- Modal Section -->
<div class="modal fade" id="modal-processing-report-data" tabindex="-1" role="dialog" aria-labelledby="modal-processing-report-data-label" aria-hidden="true" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="modal-processing-report-data-label">Processing...</h4>
</div>
<div class="modal-body">
<div class="progress progress-striped active">
<div class="progress-bar" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
</div>
</div>
</div>
</div>
</div>
</div>

Resources