I think of this as a really simple problem, but I'm having a lot of trouble finding a straight answer.
Simple use case:
Form that collects data, but does not save data to any database,
Run calculations on data (some basic math, done through the controller after 'Submit' is clicked).
Display newly calculated data on new page.
I'm having trouble figuring out how to get step 3 working. I've created a route and view, and I'm rendering it on 'Submit'. I just don't know how to use the newly calculated variables from my controller on this new page.
Any help/resources would be greatly appreciated. The end of my controller function looks something like this:
var age_upper = age + 60;
...
res.render('ageResults');
Where 'ageResults' would be the page I want to display the calculated data on.
Pass the values to the template in the 'locals' using:
res.render('ageResults', {age_upper: age_upper})
Then use #{age_upper} in ageResults.pug.
Related
I am implementing a movie search application; in which movies will be returned after clicking search.
In the result lists, user can give "like" to the movies displayed to them.
However, if the user selects to sort by like, the my sort function actually is sorting the "old" search result while some movie's number of like may be changed due to user input.
So, I would like to reload the pages so that the page will go back to the server to load new data and then do the sorting again.
May I know if there is a way to reload the pages by calling my current URL and then I add an extra param on the URL like (sort by no of like). So that I can know I should sort it by no of like in the server-side function
Or if there is a simple approach to deal with this case
Edit for better illustration
the search result is a list of movie
stage 1
1.
Titanic
like:3
2.
spiderman
like:3
stage 2 (user give a like to second one)
1.
Titanic
like:3
2.
spiderman
like:4 <----- no of like increased due to the user giving raising point)
stage 3 User suddenly wants to sort the results by no of like; then I sort the results on the fly.
1.
Titanic
like:3
2.
spiderman
like:3 <------ the results is not updated since the result is old
routing function I am using
router.push({
pathname: "/search",
query: {sort: sort}
)
but the reload is not clean. Component is still cached
[edit 2]
In each item in the result list, it is actually wrapped by an result card components
So, to sum up, the server passes the search results to the search page.
Then I iterate the results and then return a number of result cards.
In the result card, it allows users to make an action like raise like.
The reason I can keep it dynamic without calling the API is I kept these two hook.
const [likeCount, setLikeCount] = useState(movie.likeBy.length);
const [liked, setLiked] = useState(false);
But the problem is that when the user clicks the "sort by like", even it gets the new sorted search result. The result card component is still keeping previous data values. It makes the new render weird. That's why I want to make a complete reload that can clear all components' states.
And I found that router.push doesnt do the job
Hope this explains things clear
why do you need to reload the page to get new data you can do it in the same URL
let's assume your baseurl ===>>> "getmovies?sortby="
if you don't pass the value in sortby then it will fetch all data
after adding value in sortby query it will fetch sorted data
sorturl ===>>>"getmovies?sortby=like"
You can use optimistic UI (which is persistence), I have used it with GraphQL and Facebook uses something similar. As soon as a user likes a movie, React updates the cache which it uses to render the UI. It makes the API call in the background and if it is successful, the UI remains the same (hence optimistic).
Edit:
After you have updated your question, I think we can look into states. Currently you are updating states when user likes a movie but when they sort it again, we are using the old results object or array returned from the server at the first time. If we are not calling the server everytime a user sorts the results, we can store a result copy in a component state fetched from the API and consider it as a source of data for dynamic rendering. Now if a user likes a movie, you update the local state of the result object, it will cause render and updates the UI. When user try to sort the movies, you use local state which has all the latest information and sort it.
I am using NeoLoad, I am facing an issue that a dynamic value which is not in previous source pages.
I logged in as a User.
I just click on Menu Link, when I click on this menu link, a dynamic value is generating with this link.
In the above the URL the StartPage=1433433137 this is dynamic value, which is not found in any previous source pages, so when I click on link menu this URL generate a new StatPage=13232334, so how to extract this value or how to handle this.
When I verify this variable name StatPage in previous sources pages, I found in a html page as JavaScript variable is defined like var StatPage = true; and also url.open('GET','id=1&StatPage=' + startDate, true);
And another .js file is also having this variable like
if(typeof StatPage!="undefined"&&StatPage) - <some more text here>
Any one help how to handle these type of dynamic values, I am using NeoLoad Performance testing tool.
I don't have a full solution for your situation, but would like to share some thoughts that may give you some direction.
It looks like the 10 digit integer number in the query string after StartPage is a dynamic parameter created on the client as a result of executing a JavaScript function. Based on the variable name startDate it is stored in, I think there is a date-time related function. If I need to guess further, this may be the epoch time convert to seconds (see jquery convert number to date?). You can verify this with developers.
In any case, to parameterize such test case you need an option to parameterize a query string with client-side functions. You can check if NeoLoad supports, such functionality.
I'm developing a web scraper in Node JS and I'm trying to figure out the best approach to combine data from one list, with data on another list.
For example:
Step 1: Scrape data from website A
In this step, I scrape some data using cheerio/request and store this in a list, which is then displayed on the screen in a jQuery data table. The data table has a checkbox next to each scraped row of data and the value I have assigned to each checkbox is a "URL".
Step 2: Scrape again based on URLs chosen in checkboxes
In step 2, the app will scrape another website based on the URLs selected in step 1 and will retrieve some data values from these URLs that are scraped.
My dilemma
I wish to use some data values that were scraped in step 1 along with some data values scraped in step 2. However currently in my app, the data from Step 1 has been lost because it's not being saved anywhere.
Since this is a sort of dynamic search whereby a user will search for data, scrape it and then not neccessarily want to see it again, I think saving data into a database would be overkill? So I'm wondering if I should save the list data from step 1 into a session variable and then link them up together again using the URL (in the checkbox) as the key?
Thanks for your help!
Anthony
if you dont want to do saving for these data then pass it as another inputs of your form , try
< input type=hidden value=json.stringify(item)/>
I dont think using database for storage of the scrapped conetent would be an overkill.
The ideal points to note in this process would be.
Use a document store like mongoDB to dump your json data directly. I proposed mongoDB because you get more resources to refer.
Initially open up a db connection in node and your scraping deamon can reuse it for each time when it parses the http result using cheerio and dumps it to db.
Here Once you get the output from http request to your Target URL, the cheerio parse steps should take more time than dumping the data to a db.
I have followed a similar approach for scrapping movie data from imdb and you can find the corresponding code in this repo, if you are interested. I have also used cheerio and its a good selection in my opinion.
We have been developing our application using ExtJs 4.0.7, and now we have a new feature request which will allow user to set the position of form fields, as per his choice, using drag and drop.
For example, if currently a form has fields arranged in rows, then the user can pick these fields and arrange them in columns, or he can move a field from first row to second etc..
The user is also allowed to save this layout and when he opens the screen again then he gets to see the fields arranged in the same manner he saved.
I have not been able to locate any example in ExtJS carrying such a functionality, so I was wondering if this is possible in ExtJS?
Also, as the user is allowed to save the layout, thus, will this involve storing of ExtJs code in database or dynamic generation of ExtJS code from server side.
Looking forward to guidance at this.
Thanks in advance.
The only example of such a beast I have seen is the Sencha Designer. It saved the complete JSON object that represents the form config ... I suppose it's doable, but good luck :)
I am new to Drupal and trying to get hand on it.
I am not able to find how to have the following functionality on my site. If anyone can help me out, it would be great for me.
I need to have a form that will take 2 fields one of which is supposed to be the login id(how to retrive login id?). I need to store this and display in tabular form also on a new page. Lastly I want to provide an edit form for this functionality using the same form but its use will be like whenever a person adds value in this form, it checks in Table1, if entry is not present it adds in table, else it updates the table.
Apart from this I need to store all the updations in a seperate table or something like that, so that I am able to see the history of all the changes
Eg:
ADD Form:
Fields:
- LoginID
- Phone number
Show Table Page(Tabular with the stored information)
Edit Form(same as above form):
Fields:
- LoginID
- Phone number
Now If I add my phone number to this it will get stored. Later when I try to modify my number it should update in initial table but also store the history of old and new entry in a separate table so that I can perform varies options on it.
I also dont know how to add/enable form fields in drupal. :(
Thanks
I'm not entirely sure what you're asking, but I think the Computed Field module might be helpful. The module allows you to define custom hooks that run when a node is saved.
If you're not creating nodes and are using something like the Webform module, you should be able to write a module to process the data.