Best JavaScript code snippet using redwood
frmFullScreenAdsController.js
Source:frmFullScreenAdsController.js
1define({2 numOfAds : 0 ,3 currentFlex : 1 ,4 xOffset : 0 ,5 nonInfeedAds : 0 ,6 imageObjArray : [] ,7 imageDownloadFailureCount : 0 , 8 gestIDs : [] ,9 init : function(){10 var navManager = applicationManager.getNavigationManager();11 var currentForm=navManager.getCurrentForm();12 applicationManager.getPresentationFormUtility().initCommonActions(this,"YES",currentForm);13 },14 initActions : function(){15 this.view.flxCancel.onClick = this.onAdClose;16 },17 onPreShow: function() {18 this.initActions();19 this.view.statusBarHidden = true;20 var navManager = applicationManager.getNavigationManager();21 this.nonInfeedAds = navManager.getCustomInfo("frmFullScreenAds").postLoginAdData;22 this.numOfAds = this.nonInfeedAds.length;23 this.xOffset = 0;24 this.currentFlex = 1;25 this.imageDownloadFailureCount = 0;26 this.imageObjArray = [];27 if(!this.gestIDs)28 {29 this.gestIDs = [];30 }31 this.disableUntilImageDownloads();32 this.removeGestureRecognisers();33 var date = new Date();34 var param;35 var imgUrl;36 var deviceUtilManager = applicationManager.getDeviceUtilManager();37 var deviceData = deviceUtilManager.getDeviceInfo();38 for(var j = 1; j <= this.numOfAds; j++)39 {40 param=date.getTime();41 this.view["flxAd"+j].left="0dp";42 this.view["flxAd"+j].setVisibility(false);43 //Ideally for IphoneX we use @3x images,44 // But in case of postLogin full screen Ads, to achieve a better UI look45 // We are using a customised image, hence we are storing the image name with "@IphoneX" 46 // as an extension. 47 if(deviceUtilManager.getDeviceInfo().model.indexOf("iPhone X") > -1)48 {49 imgUrl = this.nonInfeedAds[j-1].imageURL+"@IphoneX.png";50 }51 else52 {53 imgUrl = deviceUtilManager.getImageURLBasedOnDeviceType(this.nonInfeedAds[j-1].imageURL);54 }55 this.view["imgAd"+j].src = imgUrl+"?Param="+param;56 }57 if(deviceData.model.indexOf("iPhone X") > -1)58 { 59 this.view.flxAdvertisement.top="-46dp";60 }61 this.view.flxScrollContainerAds.setContentOffset({62 x: this.xOffset,63 y: 064 }, true);65 applicationManager.getPresentationUtility().dismissLoadingScreen();66 var currentForm=navManager.getCurrentForm();67 applicationManager.getPresentationFormUtility().logFormName(currentForm);68 },69 getActionDetails : function(adNumber,actionNumber) {70 var interactions = this.nonInfeedAds[adNumber-1].interactions;71 if(actionNumber === 1)72 {73 return interactions[0];74 }75 else if(actionNumber === 2)76 {77 return interactions[1];78 }79 },80 onAdDownloadComplete : function(issuccess,adNumber){81 if(issuccess)82 {83 var i=this.imageObjArray.length;84 this.alignFlexInScrollContainer(i+1,adNumber);85 if(i===0)86 {87 this.enableAfterImageDownloads(adNumber);88 this.setGestureRecogniser();89 }90 this.imageObjArray[i] = adNumber;91 } 92 else93 {94 this.imageDownloadFailureCount++;95 if(this.imageDownloadFailureCount === this.numOfAds)96 {97 var logger = applicationManager.getLoggerManager();98 logger.log("####All PostLogin Ad's download failed\n####Therefore Closing Them");99 this.onAllAdsDownloadFailure();100 }101 }102 },103 enableAfterImageDownloads : function(adNumber){104 var title =null;105 var textColor =null;106 var text =null;107 var scope = this;108 if(this.isActionPresent(adNumber,1))109 {110 this.view["flxAdAction1Img"+adNumber].setVisibility(true);111 this.view["rtxLblAdAction1Img"+adNumber].setVisibility(true);112 this.view["btnAdAction1Img"+adNumber].backgroundColor = this.getActionDetails(adNumber,1).colour;113 this.view["btnAdAction1Img"+adNumber].setVisibility(true);114 title = this.getActionDetails(adNumber,1).text;115 textColor = this.getActionDetails(adNumber,1).textcolor;116 if(!textColor || textColor === "")117 {118 textColor = "#ffffff";119 }120 text = "<label style=\"color:"+textColor+"\">"+title+"</label>";121 this.view["rtxLblAdAction1Img"+adNumber].text = text;122 this.view["flxAdAction1Img"+adNumber].forceLayout();123 }124 if(this.isActionPresent(adNumber,2))125 {126 var buttonType = this.getActionDetails(adNumber,2).buttonType;127 if( buttonType === "BUTTON")128 {129 this.view["flxAdAction2Img"+adNumber].setVisibility(true);130 this.view["rtxLblAdAction2Img"+adNumber].setVisibility(true);131 this.view["btnAdAction2Img"+adNumber].backgroundColor = this.getActionDetails(adNumber,2).colour;132 this.view["btnAdAction2Img"+adNumber].setVisibility(true);133 title = this.getActionDetails(adNumber,2).text;134 textColor = this.getActionDetails(adNumber,2).textcolor;135 if(!textColor || textColor === "")136 {137 textColor = "#ffffff";138 }139 text = "<label style=\"color:"+textColor+"\">"+title+"</label>";140 this.view["rtxLblAdAction2Img"+adNumber].text = text;141 } 142 else if(buttonType === "LINK")143 {144 this.view["flxAdAction2Img"+adNumber].setVisibility(true);145 this.view["btnAdAction2Img"+adNumber].setVisibility(false);146 this.view["rtxLblAdAction2Img"+adNumber].setVisibility(true);147 title = this.getActionDetails(adNumber,2).text;148 textColor = this.getActionDetails(adNumber,2).textcolor;149 if(!textColor)150 {151 textColor = "#ffffff";152 }153 text = "<u><label style=\"color:"+textColor+"\">"+title+"</label></u>";154 this.view["rtxLblAdAction2Img"+adNumber].text = text;155 }156 this.view["flxAdAction2Img"+adNumber].forceLayout();157 }158 },159 alignFlexInScrollContainer : function (position,flxNumber){160 if(position === 1)161 {162 this.view.flxProgressBar.setVisibility(true);163 this.view["flxAd"+flxNumber].setVisibility(true);164 this.view.flxLoadingIndicator.setVisibility(false);165 }166 else167 {168 var leftVal = (position-1)*parseInt(applicationManager.getDeviceUtilManager().getDeviceInfo().screenWidth);169 this.view["flxAd"+flxNumber].left = leftVal+"dp";170 this.view["flxAd"+flxNumber].setVisibility(true);171 }172 this.view.flxScrollContainerAds.forceLayout();173 var noOfDownloadedAds = position;174 if(noOfDownloadedAds>1)175 {176 if(noOfDownloadedAds === 2)177 {178 this.view.flxProgressButton1.setVisibility(true);179 this.view.flxProgressButton2.setVisibility(true);180 this.view.flxProgressButton1.left="46%";181 this.view.flxProgressButton1.skin = "sknflxADADADRadius100px";182 this.view.flxProgressButton2.skin = "sknflxE3E3E3Radius100px";183 }184 else if(noOfDownloadedAds === 3)185 {186 this.view.flxProgressButton3.setVisibility(true);187 this.view.flxProgressButton3.skin = "sknflxE3E3E3Radius100px";188 this.view.flxProgressButton1.left="43.5%";189 }190 else if(noOfDownloadedAds === 4)191 {192 this.view.flxProgressButton4.setVisibility(true);193 this.view.flxProgressButton4.skin = "sknflxE3E3E3Radius100px";194 this.view.flxProgressButton1.left="41%";195 }196 else197 {198 this.view.flxProgressButton5.setVisibility(true);199 this.view.flxProgressButton5.skin = "sknflxE3E3E3Radius100px";200 this.view.flxProgressButton1.left="38%";201 }202 this.view.flxProgressBar.forceLayout();203 }204 },205 onAllAdsDownloadFailure : function(){206 this.view.imgLoadingIndicator.src="fullscreenaddownloadfailed.png";207 this.onAdClose();208 },209 disableUntilImageDownloads : function(){210 for(var i=1;i<6;i++)211 {212 this.view["flxAdAction1Img"+i].setVisibility(false);213 this.view["btnAdAction1Img"+i].setVisibility(false);214 this.view["rtxLblAdAction1Img"+i].setVisibility(false);215 this.view["flxAdAction2Img"+i].setVisibility(false);216 this.view["btnAdAction2Img"+i].setVisibility(false);217 this.view["rtxLblAdAction2Img"+i].setVisibility(false);218 }219 this.view.flxProgressButton1.setVisibility(false);220 this.view.flxProgressButton2.setVisibility(false);221 this.view.flxProgressButton3.setVisibility(false);222 this.view.flxProgressButton4.setVisibility(false);223 this.view.flxProgressButton5.setVisibility(false);224 this.view.flxProgressBar.forceLayout();225 this.view.flxProgressBar.setVisibility(false);226 this.view.flxLoadingIndicator.setVisibility(true);227 this.view.imgLoadingIndicator.src = "loaderfullscreen.gif";228 },229 removeGestureRecognisers : function()230 {231 if(this.gestIDs.length!==0)232 {233 var swipeGestureID = this.gestIDs[0];234 var tapGestureID = this.gestIDs[1];235 this.view.flxAdActionArea.removeGestureRecognizer(swipeGestureID);236 this.view.flxAdActionArea.removeGestureRecognizer(tapGestureID);237 this.gestIDs = [];238 }239 },240 setGestureRecogniser : function()241 {242 if(this.gestIDs.length === 0)243 {244 var swipeGestID = this.view.flxAdActionArea.setGestureRecognizer(2, {245 fingers: 1,246 swipedistance: 20,247 swipevelocity: 60248 }, this.onAdSwipe);249 var tapGestID = this.view.flxAdActionArea.setGestureRecognizer(1, {250 fingers: 1,251 taps:1252 }, this.onAdTap);253 this.gestIDs[0]=swipeGestID;254 this.gestIDs[1]=tapGestID;255 }256 this.view.flxAction1.onClick = this.onAdAction1Onclick;257 this.view.flxAction2.onClick = this.onAdAction2Onclick;258 },259 onAdSwipe : function(widget, gestureInfo, context) {260 var adNum = this.imageObjArray.length;261 var scWidth= applicationManager.getDeviceUtilManager().getDeviceInfo().screenWidth;262 var currFlex = this.currentFlex;263 var xVal = this.xOffset;264 var isThereChange = false;265 if (gestureInfo.swipeDirection === 1) {266 if (currFlex>=1 && currFlex<adNum)267 {268 isThereChange = true;269 xVal = xVal + scWidth;270 currFlex++;271 }272 } else if (gestureInfo.swipeDirection === 2) {273 if (currFlex>1 && currFlex<=adNum) {274 isThereChange = true;275 xVal = xVal - scWidth;276 currFlex--;277 } 278 }279 if(isThereChange)280 {281 this.view.flxScrollContainerAds.setContentOffset({282 x: xVal,283 y: 0284 }, true);285 var currAd = this.imageObjArray[currFlex-1];286 this.enableAfterImageDownloads(currAd);287 for (var j = 1; j <= adNum; j++) {288 if (j === currFlex){289 this.view["flxProgressButton" + j ].skin = "sknflxADADADRadius100px";290 }291 else{292 this.view["flxProgressButton" + j ].skin = "sknflxE3E3E3Radius100px";293 }294 }295 this.view.flxProgressBar.forceLayout();296 this.view.flxScrollContainerAds.forceLayout();297 this.currentFlex = currFlex;298 this.xOffset = xVal;299 }300 },301 isActionPresent : function(adNumber,actionNumber) {302 var interactions = this.nonInfeedAds[adNumber-1].interactions;303 if(actionNumber === 1)304 {305 if(interactions.length > 0)306 {307 return true;308 }309 }310 else if (actionNumber === 2)311 {312 if(interactions.length > 1)313 {314 return true;315 }316 }317 return false;318 },319 onAdTap : function(widget, gestureInfo, context){320 applicationManager.getPresentationUtility().showLoadingScreen();321 var nonInfeedAds = this.nonInfeedAds;322 var currFlex = this.currentFlex;323 var currAd = this.imageObjArray[currFlex-1];324 var navType = nonInfeedAds[currAd-1].navigationType;325 if(navType === "URL")326 {327 var url = nonInfeedAds[currAd-1].navigationURL;328 kony.application.openURL(url);329 }330 else 331 {332 kony.print("Navigation Type:"+navType);333 }334 var navId = nonInfeedAds[currAd-1].navigationId;335 var authMode = kony.mvc.MDAApplication.getSharedInstance().getModuleManager().getModule("AuthModule");336 authMode.presentationController.sendDmResponseForPostloginAds(navId);337 applicationManager.getPresentationUtility().dismissLoadingScreen();338 },339 onAdAction1Onclick : function(){340 if(!this.view.flxLoadingIndicator.isVisible)341 {342 applicationManager.getPresentationUtility().showLoadingScreen();343 var currFlex = this.currentFlex;344 var currAd = this.imageObjArray[currFlex-1];345 var navType = this.getActionDetails(currAd,1).navigationType;346 if(navType === "URL")347 {348 var navURL = this.getActionDetails(currAd,1).navigationURL;349 kony.application.openURL(navURL);350 }351 else 352 {353 kony.print("Navigation type"+navType);354 }355 var navId = this.getActionDetails(currAd,1).navigationId;356 var authMode = kony.mvc.MDAApplication.getSharedInstance().getModuleManager().getModule("AuthModule");357 authMode.presentationController.sendDmResponseForPostloginAds(navId);358 applicationManager.getPresentationUtility().dismissLoadingScreen();359 }360 },361 onAdAction2Onclick : function(){362 if(!this.view.flxLoadingIndicator.isVisible)363 {364 applicationManager.getPresentationUtility().showLoadingScreen();365 var currFlex = this.currentFlex;366 var currAd = this.imageObjArray[currFlex-1];367 var navType = this.getActionDetails(currAd,2).navigationType;368 if(navType === "URL")369 {370 var navURL = this.getActionDetails(currAd,2).navigationURL;371 kony.application.openURL(navURL);372 }373 else 374 {375 kony.print("Navigation type"+navType);376 }377 var navId = this.getActionDetails(currAd,2).navigationId;378 var authMode = kony.mvc.MDAApplication.getSharedInstance().getModuleManager().getModule("AuthModule");379 authMode.presentationController.sendDmResponseForPostloginAds(navId);380 applicationManager.getPresentationUtility().dismissLoadingScreen();381 }382 },383 onAdClose: function() {384 applicationManager.getPresentationUtility().showLoadingScreen();385 var authMode = kony.mvc.MDAApplication.getSharedInstance().getModuleManager().getModule("AuthModule");386 authMode.presentationController.sendDmResponseForPostloginAds("EXIT");387 authMode.presentationController.navigateToDashboardFromAds();388 },...
utils.js
Source:utils.js
1'use strict';2const _ = require('lodash');3/**4 * Merges5 */6const mergeSchemas = (root, ...subs) => {7 subs.forEach(sub => {8 if (_.isEmpty(sub)) return;9 const { definition = '', query = {}, mutation = {}, subscription = {}, resolvers = {} } = sub;10 root.definition += '\n' + definition;11 _.merge(root, {12 query,13 mutation,14 subscription,15 resolvers,16 });17 });18 return root;19};20const createDefaultSchema = () => ({21 definition: '',22 query: {},23 mutation: {},24 subscription: {},25 resolvers: {},26});27const diffResolvers = (object, base) => {28 let newObj = {};29 Object.keys(object).forEach(type => {30 Object.keys(object[type]).forEach(resolver => {31 if (type === 'Query' || type === 'Mutation') {32 if (!_.has(base, [type, resolver])) {33 _.set(newObj, [type, resolver], _.get(object, [type, resolver]));34 }35 } else {36 _.set(newObj, [type, resolver], _.get(object, [type, resolver]));37 }38 });39 });40 return newObj;41};42const convertToParams = params => {43 return Object.keys(params).reduce((acc, current) => {44 const key = current === 'id' ? 'id' : `_${current}`;45 acc[key] = params[current];46 return acc;47 }, {});48};49const convertToQuery = params => {50 const result = {};51 _.forEach(params, (value, key) => {52 if (_.isPlainObject(value)) {53 const flatObject = convertToQuery(value);54 _.forEach(flatObject, (_value, _key) => {55 result[`${key}.${_key}`] = _value;56 });57 } else {58 result[key] = value;59 }60 });61 return result;62};63const amountLimiting = (params = {}) => {64 const { amountLimit } = strapi.plugins.graphql.config;65 if (!amountLimit) return params;66 if (!params.limit || params.limit === -1 || params.limit > amountLimit) {67 params.limit = amountLimit;68 } else if (params.limit < 0) {69 params.limit = 0;70 }71 return params;72};73const nonRequired = type => type.replace('!', '');74const actionExists = ({ resolver, resolverOf }) => {75 if (isResolvablePath(resolverOf)) {76 return true;77 } else if (_.isFunction(resolver)) {78 return true;79 } else if (_.isString(resolver)) {80 return _.isFunction(getActionFn(getActionDetails(resolver)));81 } else {82 throw new Error(83 `Error building query. Expected \`resolver\` as string or a function, or \`resolverOf\` as a string. got ${{84 resolver,85 resolverOf,86 }}`87 );88 }89};90const getAction = resolver => {91 if (!_.isString(resolver)) {92 throw new Error(`Error building query. Expected a string, got ${resolver}`);93 }94 const actionDetails = getActionDetails(resolver);95 const actionFn = getActionFn(actionDetails);96 if (!actionFn) {97 throw new Error(98 `[GraphQL] Cannot find action "${resolver}". Check your graphql configurations.`99 );100 }101 return actionFn;102};103const getActionFn = details => {104 const { controller, action, plugin, api } = details;105 if (plugin) {106 return _.get(strapi.plugins, [_.toLower(plugin), 'controllers', _.toLower(controller), action]);107 }108 return _.get(strapi.api, [_.toLower(api), 'controllers', _.toLower(controller), action]);109};110const getActionDetails = resolver => {111 if (resolver.startsWith('plugins::')) {112 const [, path] = resolver.split('::');113 const [plugin, controller, action] = path.split('.');114 // return { plugin, controller, action };115 return { source: 'plugins', plugin, controller, action };116 }117 if (resolver.startsWith('application::')) {118 const [, path] = resolver.split('::');119 const [api, controller, action] = path.split('.');120 // return { api, controller, action };121 return { source: 'application', api, controller, action };122 }123 const args = resolver.split('.');124 if (args.length === 3) {125 const [api, controller, action] = args;126 return { api, controller, action };127 }128 // if direct api access129 if (args.length === 2) {130 const [controller, action] = args;131 return { api: controller, controller, action };132 }133 throw new Error(134 `[GraphQL] Could not find action for resolver "${resolver}". Check your graphql configurations.`135 );136};137const isResolvablePath = path => _.isString(path) && !_.isEmpty(path);138module.exports = {139 diffResolvers,140 mergeSchemas,141 createDefaultSchema,142 convertToParams,143 convertToQuery,144 amountLimiting,145 nonRequired,146 actionExists,147 getAction,148 getActionDetails,149 getActionFn,150 isResolvablePath,...
Using AI Code Generation
1var redwood = require('redwood');2client.GetActionDetails('test', function(err, result) {3 if (err) {4 console.log(err);5 } else {6 console.log(result);7 }8});9var redwood = require('redwood');10client.GetActionDetailsByType('test', 'test', function(err, result) {11 if (err) {12 console.log(err);13 } else {14 console.log(result);15 }16});17var redwood = require('redwood');18client.GetActionDetailsByStatus('test', 'test', function(err, result) {19 if (err) {20 console.log(err);21 } else {22 console.log(result);23 }24});25var redwood = require('redwood');26client.GetActionDetailsByTypeAndStatus('test', 'test', 'test', function(err, result) {27 if (err) {28 console.log(err);29 } else {30 console.log(result);31 }32});
Using AI Code Generation
1var redwood = require('redwood');2var actionDetails = redwood.GetActionDetails('actionName');3console.log(actionDetails);4var redwood = require('redwood');5var actionDetails = redwood.GetActionDetails('actionName');6console.log(actionDetails);
Using AI Code Generation
1var redwood = require('redwood');2redwood.init('redwood');3var action = 'com.redwood.rwt.action.CreateAction';4var actionDetails = redwood.GetActionDetails(action);5console.log(actionDetails);6{ action: 'com.redwood.rwt.action.CreateAction',7 actionToolbarSeparator: 'Create' }
Using AI Code Generation
1var action = "GetActionDetails";2var inputs = {3}4var response = context.ExecuteWorkflowAction(action, inputs);5var result = JSON.parse(response.Result);6if (response.IsSuccess) {7 if (result.IsSuccess) {8 var actionDetails = result.Result;9 var actionName = actionDetails.ActionName;10 var actionDescription = actionDetails.ActionDescription;11 var actionId = actionDetails.ActionId;12 var actionType = actionDetails.ActionType;13 var actionParameters = actionDetails.ActionParameters;14 var actionReturnParameters = actionDetails.ActionReturnParameters;15 var actionReturnValues = actionDetails.ActionReturnValues;16 var actionReturnValue = actionDetails.ActionReturnValue;17 var actionReturnValueType = actionDetails.ActionReturnValueType;18 var actionReturnValueDescription = actionDetails.ActionReturnValueDescription;19 var actionReturnValueExample = actionDetails.ActionReturnValueExample;20 var actionReturnValueRequired = actionDetails.ActionReturnValueRequired;21 var actionReturnValueDefault = actionDetails.ActionReturnValueDefault;22 var actionReturnValueOptions = actionDetails.ActionReturnValueOptions;23 var actionReturnValueOptionsDescription = actionDetails.ActionReturnValueOptionsDescription;24 var actionReturnValueOptionsExample = actionDetails.ActionReturnValueOptionsExample;25 var actionReturnValueOptionsRequired = actionDetails.ActionReturnValueOptionsRequired;26 var actionReturnValueOptionsDefault = actionDetails.ActionReturnValueOptionsDefault;27 var actionReturnValueOptionsType = actionDetails.ActionReturnValueOptionsType;28 var actionReturnValueOptionsIsList = actionDetails.ActionReturnValueOptionsIsList;29 var actionReturnValueOptionsListType = actionDetails.ActionReturnValueOptionsListType;30 var actionReturnValueOptionsListTypeDescription = actionDetails.ActionReturnValueOptionsListTypeDescription;31 var actionReturnValueOptionsListTypeExample = actionDetails.ActionReturnValueOptionsListTypeExample;32 var actionReturnValueOptionsListTypeRequired = actionDetails.ActionReturnValueOptionsListTypeRequired;33 var actionReturnValueOptionsListTypeDefault = actionDetails.ActionReturnValueOptionsListTypeDefault;34 var actionReturnValueOptionsListTypeType = actionDetails.ActionReturnValueOptionsListTypeType;35 var actionReturnValueOptionsListTypeIsList = actionDetails.ActionReturnValueOptionsListTypeIsList;36 var actionReturnValueOptionsListTypeListType = actionDetails.ActionReturnValueOptionsListTypeListType;37 var actionReturnValueOptionsListTypeListTypeDescription = actionDetails.ActionReturnValueOptionsListTypeListTypeDescription;38 var actionReturnValueOptionsListTypeListTypeExample = actionDetails.ActionReturnValueOptionsListTypeListTypeExample;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!