coffeescript update url if contains string - url

I'm trying to change url if it contains the word 'register'. I can do this, but the page continues to loop and doesn't stop. Does anyone know how I can get the page to update to .../register?bypass_verification=true without making the page continuously loop? Thanks
if window.location.href.indexOf("register") > -1
window.location.href = 'register'+ '?bypass_verification=true'
return

Your if condition is matching your new URL once you've redirected back with the bypass_verification parameter set. Since this still matches your condition, you are getting what appears to be a loop. You need to change your logic so that window.location.href doesn't get reassigned if it already contains bypass_verification=true.
Here is one approach that should work:
if window.location.href.indexOf("register") > -1
window.location.href = 'register'+ '?bypass_verification=true' unless window.location.href.indexOf("?bypass_verification=true") > 0
return

Related

How do I add url links to WinWheel.js image slices?

How do I add a clickable link to any of the image slices so the user can click a slice to go to a url? Currently they can spin the wheel to get a random url choice. I got the random spin part working using “IF” but I got stuck figuring out the image slice click idea.
I'm currently working at the top of page in an area called:
//add code here?
if (clickedSegment) {
clickedSegment.indicatedSegment = "Jane";
window.location = "https://www.mikeloucas.com";
theWheel.draw();
and I have one url working due to the "clickedSegment" but it's active on all the slices and not what I need (I'm try to target Jane) so I'll keep at it unless some has an answer.
Separately but related:
This is one of the image segments I'm trying to add add link to:
{'image' : 'https://mikeloucas.com/wheel/jane.png', 'text' : 'Jane'},
The original tutorial shows how to change the colour of a slice on click, but I’d like to go to a url instead.
Original Click Code: http://dougtesting.net/winwheel/docs/tut15_get_segment_clicked
The thing Im working on: https://codepen.io/mikeloucas/pen/qBarWoP
In my Codepen example I turned off the “IF” load url because its just in the way when testing, but feel free to turn it on see it in action. It’s WAY down the page lol; you’ll see:
if (indicatedSegment.text == "Jane") {
window.location = "https://www.mikeloucas.com";
WAS:
let clickedSegment= theWheel.getSegmentAt(e.clientX, e.clientY);
if (clickedSegment) {
clickedSegment.indicatedSegment = "Jane";
window.location = "https://www.mikeloucas.com";
theWheel.draw();
IS NOW:
let segmentImage = theWheel.getSegmentAt(e.clientX, e.clientY);
if (segmentImage.text == "Jane") {
window.location = "https://www.mikeloucas.com";}
else if (segmentImage.text == "othername")...{
}
...theWheel.draw();
The trick (for me) was changing "clickedSegment" to "segmentImage" because "segmentImage" was already calling the array of names. I also add an "ELSE IF" because I had lots of slices to work work with.
See working thingy here: https://codepen.io/mikeloucas/pen/qBarWoP
My version needs to have the URL and NAME LIST entered twice; it would be cool if someone knows how to do it once (one set instead of two) but maintain both functions of the "CLICK url" and "SPIN url", so I'm still open to advice.
I'd prefer one set over two. :-)

php str_replace produces strange results

I am trying to replace some characters in a text block. All of the replacements are working except the one at the beginning of the string variable.
The text block contains:
[FIRST_NAME] [LAST_NAME], This message is to inform you that...
The variables are defined as:
$fname = "John";
$lname = "Doe";
$messagebody = str_replace('[FIRST_NAME]',$fname,$messagebody);
$messagebody = str_replace('[LAST_NAME]',$lname,$messagebody);
The result I get is:
[FIRST_NAME] Doe, This message is to inform you that...
Regardless of which tag I put first or how the syntax is {TAG} $$TAG or [TAG], the first one never gets replaced.
Can anyone tell me why and how to fix this?
Thanks
Until someone can provide me with an explanation for why this is happening, the workaround is to put a string in front and then remove it afterward:
$messagebody = 'START:'.$messagebody;
do what you need to do
$messagebody = substr($messagebody,6);
I believe it must have something to do with the fact that a string starts at position 0 and that maybe the str_replace function starts to look at position 1.

eVar value not getting passed in s.tl call

I have a page that contains a login form. I am calling a separate function (which resides in a separate .js file) on the onsubmit event of the form. Below is the function
var LoginClick = function() {
// Omniture Code
s.linkTrackVars="events, eVar1";
s.linkTrackEvents="event1";
s.events="event1";
s.eVar1="Login";
s.tl(true, "o", "Login Clicks");
};
while the events data is getting passed on the s.tl call, the evar1 value turns up as "none" in the conversion report. I used a packet sniffer (omnibug) to check the values being passed. Even though s.eVar1 is assigned the value "Login" it does not pass that value.
Ofcourse, s.t() works well (evar value gets passed) but I dont want to do that.
I have tried s.tl(this, "o"...) which doesnt work either.
What am I doing wrong here?
Appreciate your time and help.
remove the space between the comma and eVar1
s.linkTrackVars="events, eVar1"
should be
s.linkTrackVars="events,eVar1"

Querying local cache first before querying server in Breeze JS

I have an app using Breeze to query the data. I want to first check the local cache and then the server cache if no results are returned (I followed John Papa's SPA jumpstart course). However, I have found a flaw in my logic which I am not sure how to fix. Assuming I have 10 items that match my query.
Situation 1 (which works): I go to list page (Page A) displaying all 10. Hits server as cache is empty and adds all 10 to the cache. Then go to page displaying 1 result (Page B) which is found in the cache. So all good.
Situation 2 (the problem): I go to the page displaying 1 record first (Page B). Then I go to my list page (Page A) which checks the cache and finds 1 record and because of this line ( if (recordsInCache.length > 0)) it exits and only shows that 1 record.
I somehow need to know that there are more records on the server (9) that are NOT in the cache, ie. the total records for this query is actually 10, I have 1 therefore I have to hit server for the other 9.
Here is my query for Page A:
function getDaresToUser(daresObservable, criteria, forceServerCall)
{
var query = EntityQuery.from('Dares')
.where('statusId', '!=', enums.dareStatus.Deleted)
.where('toUserId', '==', criteria.userId)
.expand("fromUser, toUser")
.orderBy('deadlineDate, changedDate');
return dataServiceHelper.executeQuery(query, daresObservable, false, forceServerCall);
}
and here is my query for Page B (single item)
function getDare(dareObservable, criteria, forceServerCall)
{
var query = EntityQuery.from('Dares')
.expand("fromUser, toUser")
.where('dareId', '==', criteria.dareId);
return dataServiceHelper.executeQuery(query, dareObservable, true, forceServerCall);
}
function executeQuery(query, itemsObservable, singleEntity, forceServerCall)
{
//check local cache first
if (!manager.metadataStore.isEmpty() && !forceServerCall)
{
var recordsInCache = executeLocalQuery(query, itemsObservable, singleEntity);
if (recordsInCache.length > 0)
{
callCompleted();
return Q.resolve();
}
}
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
}
function executeLocalQuery(query, itemsObservable, singleEntity)
{
var recordsInCache = manager.executeQueryLocally(query);
if (recordsInCache.length > 0)
{
processQueryResults(recordsInCache, itemsObservable, singleEntity, true);
}
return recordsInCache;
}
Any advice appreciated...
If you want to just hit the server for comparison purposes then at some point (either when loading up your app or when you hit the list page) call inlineCount to compare total on server vs what you already have like shown in this answer stackoverflow.com/questions/16390897/counts-in-breeze-js/…
A way you can use this creatively while you are querying for the single record would be like this -
Set some variable in your view model or somewhere equal to total count
var totalCount = 0;
When you query the single record get the inline count -
var query = EntityQuery.from('Dares')
.expand("fromUser, toUser")
.where('dareId', '==', criteria.dareId)
.inlineCount(true);
and set totalCount = data.inlineCount; Same thing when you get the total items list, just set the totalCount to inlineCount then too so you always know if you have all of the entities.
I’ve been thinking about this problem more in the last year (and have since moved from Durandal + Breeze to Angular + Breeze : In Angular you can cache the service call easily using
return $resource(xyz + params}, {'query': { method:'GET', cache: true, isArray:true }}).query(successArrayDataLoad, errorDataLoad);
I guess Angular caches the params of this query and knows when it has it already. So when I switch this method to use Breeze I lose this functionality and all my List calls are hit on every time.
So the real problem here is List data. Single Entities can always check the local cache and if nothing is returned then check the server (because you expect exactly 1).
However, List data varies by params. For example, if I have a GetGames call which takes in a CreatedByUserId, every time I supply a new CreatedByUserId I have to go back to the server.
So I think what I really need to do here to cache my List calls is to cache the Key for each call which is a combination of the QueryName and the Params.
For example, GetGames1 for UserID 1 and then GetGames2 for UserId 2.
The logic would be: Check the Angular cache to see if this call has been made before in this session. If it has, then check the local cache first. If nothing is returned, check the server.
If it has not, check the server as the local cache MIGHT have some data in it for this query but it's not guaranteed to be the full set.
The only other way around it would be to hit the server each time first to get a count for that Query + Params and then hit the local cache and compare the count, but that is more inefficient.
Thoughts?

codeigniter display warning error if argument in URL not provided

If I don't provide the value in the URL for Codeigniter, it'll display a PHP Error was encountered saying it's missing argument for a function call. I do NOT want it displayed at all. If there's no argument in the URL, it should just reroute to its index function. How do I prevent that from happening?
For example, www.example.com/profile/id/45
anyone would guess and enter like this "www.example.com/profile/id"
that would generate the error. How do I prevent that? I tried, "if (!isset($id))" but it generated error before it reached to that condition.
just learned that the solution is simple:
function id($id=NULL)
{
if ($id===NULL)
{
redirect....
}
}
you can also use:
$this->uri->segment(2); // gets 'id'
$this->uri->segment(3); // gets '45'
then do a redirect, check out:
http://codeigniter.com/user_guide/helpers/url_helper.html
use default values for your function
function id($id=0){
if(there any record with $id being provided){
//do something
}else{
//id not provided,set to default values 0 and then
show_404();
}
}
no way there could be id = 0 so its automatically showerror without redirect, if user enter the url www.example.com/profile/id ,

Resources