Show and close dynamically created dialog in angularjs - angularjs

I have scenarios which are created dynamically by clicking Add Scenario button. Initially 1 scenario will be there and then user can add 4 scenarios. Maximum 5 scenarios can be added. Each scenario has a calculator icon and by clicking it, it will show a calculator popup.
If user clicks calculator icon on a particular scenario, it should show only particular scenario's calculator popup; and if user clicks close, it should close the popup.
I'm passing scenarios.Id in showCalculatorPopup(scenarios.Id) and CloseCalculatorPopup(scenarios.Id) and with scenarios.Id i'm trying to open and close particular scenario's popup.
My issue is if I click a calculator icon in scenario 1, popup is being opened in all scenarios. I tried using eval(), window[] to no avail.
Updated the code.
Instead of Switch Case i'm using
vm.showCalculatorPopup = function (ScenarioId) {
vm['calculatorPopup' + ScenarioId] = true;
}
Added break;. Even after adding break it's not working properly. When i open and close calculator for 1st time in scenario 1 then its working fine.
But when i add scenario 2 and click calculator icon, its shows the popup and when i click close in scenario 1 popup it close the scenario 2 popup.
Can't use index because button is inside the Licenceplates and its inside the Sections and its inside the Scenarios.
<div data-ng-app="ang" data-ng-controller="InputController as input">
<div data-ng-repeat="scenarios in input.model.Scenarios"> <!-- Scenario Id = 1, 2, 3, 4, 5 -->
<div data-ng-repeat="sections in scenarios.Sections">
<div data-ng-repeat="licensePlates in sections.LicensePlates">
<button data-ng-click="input.showCalculatorPopup(scenarios.Id)">Calculate</button>
<div data-ng-show="input.calculatorPopup{{scenarios.Id}}">
Dialog Box
<button data-ng-click="input.CloseCalculatorPopup(scenarios.Id)"></button>
</div>
</div>
</div>
</div>
</div>
Latest Angular Controller
vm.showCalculatorPopup = function (ScenarioId) {
vm['calculatorPopup' + ScenarioId] = true;
}
vm.showCalculatorPopup = function (ScenarioId) {
vm['calculatorPopup' + ScenarioId] = false;
}
Previous Angular Controller
vm.showCalculatorPopup = function (ScenarioId) {
vm.eval('calculatorPopup' + ScenarioId) = true;
// or
vm.window['calculatorPopup' + ScenarioId] = true;
vm.calculatorPopup1 = true; // working
// or
switch (ScenarioId) {
case 1:
vm.calculatorPopup1 = true;
break;
case 2:
vm.calculatorPopup2 = true;
break;
case 3:
vm.calculatorPopup3 = true;
break;
case 4:
vm.calculatorPopup4 = true;
break;
case 5:
vm.calculatorPopup5 = true;
break;
}
}
vm.CloseCalculatorPopup = function (ScenarioId) {
switch (ScenarioId) {
case 1:
vm.calculatorPopup1 = false;
break;
//case 3 ,4
case 5:
vm.calculatorPopup2 = false;
break;
}
}

Your switch cases are never breaking, so you are executing every later case.
switch (ScenarioId) {
case 1:
vm.calculatorPopup1 = true;
break;
case 2:
vm.calculatorPopup2 = true;
break;
case 3:
vm.calculatorPopup3 = true;
break;
case 4:
vm.calculatorPopup4 = true;
break;
case 5:
vm.calculatorPopup5 = true;
break;
}
You have the same problem with the other swtich. More info on this.

you could pass $index instead of scenarios.Id. finally you need to add a break statement in your switch statements
switch (ScenarioId) {
case 1:
vm.calculatorPopup1 = true;
break;
case 2:
vm.calculatorPopup2 = true;
break;
case 3:
vm.calculatorPopup3 = true;
break;
case 4:
vm.calculatorPopup4 = true;
break;
case 5:
vm.calculatorPopup5 = true;
break;
}
}
vm.CloseCalculatorPopup = function (ScenarioId) {
switch (ScenarioId) {
case 1:
vm.calculatorPopup1 = false;
break;
case 2:
vm.calculatorPopup2 = false;
break;
}
}
break stops the evaluation of your switch statement.

Related

How to use fields and variables to save data permanently in Google Actions with Dialogflow?

I'm trying to build up a timetable-Google-Action. The Action is supposed to tell all the subjects of a certain day when calling.
The Problem is, how do I save the data permanently on my device to access the data at any time?
I tried to declare fields in the fulfillment NODE.JS-File, but that did not worked at all. (I realised that it was a really stupid idea, as the code does not work as a 'programm', so there is no compiled stuff running in the background).
The next thing I tried was the code snippet on the Google-Developer website (https://developers.google.com/actions/assistant/save-data#df_nodejs) -> Snippet 1
I don't have any further knowledge of Java-Script or Node.JS or Google Actions in Dialogflow, but my teacher told us to develop an application without giving any information about that topic.
You can see my Fulfillment Code in Snippet 2
Snippet 1
function simpleResponse(conv) {
conv.user.storage.count = 1;
conv.ask('When is your birthday?');
}
Snippet 2
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
/* FUNCTIONS */
function getSubjects(agent) {
const date = agent.parameters.date;
const dateIso = new Date(date);
const weekDayInt = dateIso.getDay();
var dayString = '';
switch (weekDayInt){
case 0: dayString='Sonntag';
var output = agent.user.storage.sun.join(' ');
break;
case 1: dayString='Montag';
var output = agent.user.storage.mon.join(' ');
break;
case 2: dayString='Dienstag';
var output = agent.user.storage.tue.join(' ');
break;
case 3: dayString='Mittwoch';
var output = agent.user.storage.wed.join(' ');
break;
case 4: dayString='Donnerstag';
var output = agent.user.storage.thu.join(' ');
break;
case 5: dayString='Freitag';
var output = agent.user.storage.fri.join(' ');
break;
case 6: dayString='Samstag';
var output = agent.user.storage.sat.join(' ');
break;
}
agent.add(`This message is from Dialogflow's Cloud Functions for Firebase editor!`);
agent.add(new Card({
title:`Dein Stundenplan für `+dayString+`:`,
//imageUrl: 'https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png',
text: 'Du hast heute'+output+' .',
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
})
);
agent.add(new Suggestion(`Stundenplan für heute`));
agent.add(new Suggestion(`Stundenplan für morgen`));
}
function setSubject(agent){
const subject = agent.parameters.subject;
const date = agent.context.get('date');
const dateIso = new Date(date);
const weekDayInt = dateIso.getDay();
var dayString = '';
switch (weekDayInt){
case 0: dayString='Sonntag';
agent.user.storage.sun.push(subject);
break;
case 1: dayString='Montag';
agent.user.storage.mon.push(subject);
break;
case 2: dayString='Dienstag';
agent.user.storage.tue.push(subject);
break;
case 3: dayString='Mittwoch';
agent.user.storage.wed.push(subject);
break;
case 4: dayString='Donnerstag';
agent.user.storage.thu.push(subject);
break;
case 5: dayString='Freitag';
agent.user.storage.fri.push(subject);
break;
case 6: dayString='Samstag';
agent.user.storage.sat.push(subject);
break;
}
}
let intentMap = new Map();
intentMap.set('Stundenplan', getSubjects);
intentMap.set('WhichSubject', setSubject);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});
/////
UPDATE
/////
I now tried your code, but it did not functioned at all. Google interpretes the day wrong whithout any changes of the code (I'm a bit confused) and the string (whith the subjects) can't be saved neither.
It would be great if you'll take a loook at my new fulfillment code again and tell me what is wrong.
Snippet 3
'use strict';
const functions = require('firebase-functions');
const {dialogflow, BasicCard, Suggestions} = require('actions-on-google');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
const app = dialogflow();
app.intent('GetTimeTable', (conv, {date}) => {
const dateIso = new Date(date);
const weekDayInt = dateIso.getDay();
let dayString = '';
let output = '';
switch (weekDayInt) {
case 0:
dayString = 'Sonntag';
output = conv.user.storage.sun;
break;
case 1:
dayString='Montag';
output = conv.user.storage.mon;
break;
case 2:
dayString='Dienstag';
output = conv.user.storage.tue;
break;
case 3:
dayString='Mittwoch';
output = conv.user.storage.wed;
break;
case 4:
dayString='Donnerstag';
output = conv.user.storage.thu;
break;
case 5:
dayString='Freitag';
output = conv.user.storage.fri;
break;
case 6:
dayString='Samstag';
output = conv.user.storage.sat;
break;
}
conv.ask(`Du hast am ${dayString} ${output}`);
conv.ask(new BasicCard({
title: `Dein Studenplan für ${dayString}:`,
text: `Du hast ${dayString} ${output}.`,
}));
});
app.intent('WhichSubject', (conv, {date, subject}) => {
const dateIso = new Date(date);
const weekDayInt = dateIso.getDay();
let dayString = '';
//conv.user.storage.sun = 'Deutsch';
switch (weekDayInt){
case 0:
dayString='Sonntag';
conv.user.storage.sun = ''+subject;
break;
case 1:
dayString='Montag';
conv.user.storage.mon = ''+subject;
break;
case 2:
dayString='Dienstag';
conv.user.storage.tue = subject;
break;
case 3:
dayString='Mittwoch';
conv.user.storage.wed = subject;
break;
case 4:
dayString='Donnerstag';
conv.user.storage.thu = subject;
break;
case 5:
dayString='Freitag';
conv.user.storage.fri = subject;
break;
case 6:
dayString='Samstag';
conv.user.storage.sat = subject;
break;
}
conv.ask(`Am ${dayString} das Fach ${subject}.`);
conv.ask(new BasicCard({
title: `Neu gespeichert:`,
text: `Am ${dayString} das Fach ${subject}.`,
}));
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Your main issue is that in the first snippet it assumes the actions-on-google library instead of the dialogflow-fulfillment library.
The userStorage feature is only available for Actions on Google, so you would need to transition all of your code to use actions-on-google instead of dialogflow-fulfillment.
Here's a quick example of how you could adjust your code to use the library. This is not a complete set of changes, but should help you get started.
const functions = require('firebase-functions');
const {dialogflow, BasicCard, Suggestions} = require('actions-on-google');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
const app = dialogflow();
app.intent('Stundenplan', (conv, {date}) => {
const dateIso = new Date(date);
const weekDayInt = dateIso.getDay();
let dayString = '';
let output = '';
switch (weekDayInt) {
case 0:
dayStrin = 'Sonntag';
output = conv.user.storage.sun.join(' ');
break;
// ...
}
conv.ask('This message is from the Dialogflow Cloud Function for Firebase editor');
conv.ask(new BasicCard({
title: `Dein Studenplan für ${dayString}:`,
text: `Du hast heute ${output}.`,
buttonText: 'This is a button',
buttonUrl: 'https://assistant.google.com/'
}));
conv.ask(new Suggestions('Stundenplan für heute', 'Stundenplan für morgen'))
})
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

angularjs Array push Not working in switch statement

Angular js Push array not working in switch case it update last added element only
vm.saveModalData = function(title) {
if (!$scope.parentCtrl.docsList[vm.newDocObj.document_category]){
$scope.parentCtrl.docsList[vm.newDocObj.document_category] = [];
}
if(!title){
title = vm.docFileName;
$scope.parentCtrl.docsList[vm.newDocObj.document_category].push(vm.docFileName);
} else {
$scope.parentCtrl.docsList[vm.newDocObj.document_category].push(title);
}
var doc_obj = {};
doc_obj.title = title;
doc_obj.type = appConstants.DOCUMENT_CATEGORY[selectedCategory];
doc_obj.data = vm.newDocObj.document;
switch(selectedCategory) {
case 'PAN':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
$scope.parentCtrl.completeDetails.pan_document = true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+1].enabled=true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+2].enabled=true;
break;
case 'Aadhaar':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
$scope.parentCtrl.completeDetails.aadhar_document = true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+1].enabled=true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+2].enabled=true;
break;
case 'Driving License':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
$scope.parentCtrl.completeDetails.driving_license_document = true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+1].enabled=true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+2].enabled=true;
break;
case 'Passport':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
$scope.parentCtrl.completeDetails.passport_document = true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+1].enabled=true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+2].enabled=true;
break;
case 'Voter Id':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
$scope.parentCtrl.completeDetails.voter_id_document = true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+1].enabled=true;
$scope.parentCtrl.tabsList[$scope.parentCtrl.activeTab+2].enabled=true;
break;
case 'Company IT Returns':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
break;
case 'Company PAN':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
break;
case 'ITR/VAT Returns/ST Returns':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
break;
case 'Other':
$scope.parentCtrl.completeDetails.documents.push(doc_obj);
break;
default:
break;
}
vm.closeModal();
}
How to fix this issue?
I try to add first document it added into array then i added one more document but it remove existing and add as a new.
Declare your array in parent controller and use $emit on $on for passing data between child to parent controller. Try like below.
function docLpController($scope, $q, appConstants, $uibModal, utils) {
var vm = this;
$scope.parentCtrl = $scope.$parent.finwizzCtrl;
$scope.parentCtrl.completeDetails.documents = []; // declared
$scope.$on('sendData', function (event, data) {
$scope.parentCtrl.completeDetails.documents.push(data);
});
vm.saveModalData = function(title){
$scope.$emit('sendData', doc_obj);
}
Try this,
You are calling docCtrl.openAddDocModal(doc) function, while adding each and every time of Document add. Inside that function only you have initialised your array.
$scope.parentCtrl.completeDetails.documents = [];
so that each and every time it's getting reinitialised with empty.
Add this code line out side of the $uibModal.open(), recommended add below $scope.arr = [];
hope it will work...

Extjs - newbie, Switch case function not working

In this following code I am getting the desired output
fn: function(btn) {
switch(btn){
case 'yes':
Ext.Msg.prompt('Milton', 'Where is it?');
break;
case 'no':
Ext.Msg.alert('Milton',
'Im going to burn the building down!');
break;
case 'cancel':
Ext.Msg.wait('Saving tables to disk...','File Copy');
break;
}
}
This Works just fine. Now i am trying to do a function call in the switch 'yes' but i don't get any output in the screen.
This is the code i am using.
case 'yes':
Ext.Msg.prompt('Milton', 'Where is it?', function(btn,txt)
{
if (txt.toLowerCase() == 'the office') {
Ext.get('my_id').dom.innerHTML = 'Dull Work';
}else{
Ext.get('my_id').dom.innerHTML = txt;
}
Ext.DomHelper.applyStyles('my_id',{
background: 'transparent
url(images/stapler.png) 50% 50% no-repeat'
});
});
break;
Using this code inside the swich case 'yes' , i am getting a blank screen. Even the dialog box has dissapeared. Please help.
It is a very basic javascript error. A string cannot extend over the end of the line. This will work.
case 'yes':
Ext.Msg.prompt('Milton', 'Where is it?', function(btn,txt){
if (txt.toLowerCase() == 'the office') {
Ext.get('my_id').dom.innerHTML = 'Dull Work';
}else{
Ext.get('my_id').dom.innerHTML = txt;
}
Ext.DomHelper.applyStyles('my_id',{
background: 'transparent url(images/stapler.png) 50% 50% no-repeat'
});
});
break;
In the console I got the error SyntaxError: Unexpected token ILLEGAL

Using switch on $_GET with if

So I'm trying basically to make it like: ?p=blabla&dep=blabla
switch($_GET['p'])
{
case 'home':
include("template/index.html");
break;
case null:
include("template/index.html");
break;
case 'roster':
include("template/roster.html");
break;
case 'about':
include("template/about.html");
break;
case 'members':
include("members/index.php");
break;
}
if(($_GET['p'] == 'about') && ($_GET['dep'] == 'hospital'))
{
include("template/hospital.html");
}
And it still includes both about.html and hospital.html when I do blablabla?p=about&dep=hospital
How can I fix this?
Just put the if statement inside the switch case.
case 'about':
if ($_GET['dep'] == 'hospital')
include("template/hospital.html");
else
include("template/about.html");
break;
This is exactly what you ask for.
First you have your switch statement. It sees there is 'about' in $_GET['p'] so it will include that script.
Afterwards you have your if and this also evaluates to true, thus it's included.
To change this:
add another if in your 'about' case.
case 'about':
if ($_GET['dep'] == 'hospital') break;
include("template/about.html");
break;
Your switch is rocessed before the line that looks for dep=hospital, so it will include about.html before it even looks for the department.
If you want to display just hospital.html, but only if p=about move the test into the case.
switch($_GET['p'])
{
case 'home':
include("template/index.html");
break;
case null:
include("template/index.html");
break;
case 'roster':
include("template/roster.html");
break;
case 'about':
if(($_GET['dep'] == 'hospital')) {
include("template/hospital.html");
} else {
include("template/about.html");
}
break;
case 'members':
include("members/index.php");
break;
}

combo box formula item and value

I have the following formula in a Combo Box:
var keyObj = getComponent('ACConditionToggle');
var key = keyObj.getSubmittedValue();
if (!key || key==''){
key = keyObj.getValue();
}
switch(key)
{
case 'Approval':
return ['% Approval' , 'Approvers']
break;
case 'Denial':
return ['% Denial', 'Deniers']
default:
return new Array();
}
It works fine, however, I want to have labels different from the value. SO in this case with the label '% Approval' I want a value of 'Percent' and for for 'Approvers' the value of 'Number'
So how do I pass the label and the value from a formula. I can do that with static and get itemLabel and itemValue but how do I differential them in the formula?
after beating my head against the wall I found the answer to be so simple.
var keyObj = getComponent('ACConditionToggle');
var key = keyObj.getSubmittedValue();
var rtnArray = new Array();
if (!key || key==''){
key = keyObj.getValue();
}
switch(key)
{
case 'Approval':
rtnArray[0]="% Approval|Percent";
rtnArray[1]="Approver(s)|Number";
return rtnArray;
break;
case 'Denial':
rtnArray[0]="% Denial|Percent";
rtnArray[1]="Denials(s)|Number";
return rtnArray;
break
default:
return new Array();
}

Resources