Meteor easy search and iron-router - javascript

I'm using this easy serach for my project https://github.com/matteodem/meteor-easy-search
my search Index
EasySearch.createSearchIndex('searchIndex', {
'collection' : blog,
'field' : ['title', 'tags'],
'limit' : 20,
"use":"mongo-db",
'query' : function (searchString) {
// Default query that will be used for searching
var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString);
return query;
}
});
and now I have search box and when User enters something and click on enter I want to route to search page
this.route("search",{
path:'/search/:slug',
waitOn:function(){
//here I want the search data to be sent to search page
var query=this.params.slug;
EasySearch.search('searchIndex', query, function (err, data) {
console.log(data);
});
},
data:function(){
}
});
In this router I want the searchIndex data to be sent to search page, how to do this
my click event
'submit .search':function(e){
e.preventDefault();
var quer=$("#query").val();
// Router.go('search');
}
UPDATE
My main question is in the router waiton function how we get the data in callback and send it to the search page?

In your click event handler, you have commented out the line: Router.go('search').
If you write
Router.go('search', {slug: quer})
That would route you to the search page with the query data collected from the page, if that is what you want.

Related

How to redirect to new route when click on anchor tag using JS?

I have an anchor tag in an `EJs file-
<a href="/posts/" tile>Read More</a>
And a route in app.js file-
app.get('/posts/:userId', function (request6, response6) {
var resquestedTitle = _.lowerCase(request6.params.userId);
// For each postObject(elements)inside posts array we check the if condition
posts.forEach(function (elements) {
// Inside {} we have access to individual postObjects inside posts array
// From the compose
var storedTitle = _.lowerCase(elements.tile);
// Checking for each postObject whether if storedTitle matches the requested title
if (resquestedTitle === storedTitle) {
// When the requestedTitle matches the storedTitle(tile of postObject), only then we render the post page
// Rendering post.ejs using respose6.render method, post is the name of page we want to render
response6.render('post', {
// Inside {} we pass in JavaScript objects with key value pair
// actualPosts and elements.tile are key value pair
actualPosts: elements.tile,
postContent: elements.bodytext,
id: request6.params.userId,
});
} else {
console.log('Match Not Found' + resquestedTitle);
}
});
});
Here is the anchor tag on which click I want to redirect to some route i.e /posts/anything.
Read More

Remove session params if dropdown value changed

Is it possible to delete session[:sth] using jQuery/Javascript ?
In the Rails controller I set the session parameters:
def new
#other logic (...)
session[:patient_id_to_add_caregiver] = params[:patient_to_caregiver]
end
Below I've got simple function to handle case when the user selects one field from dropdown list, search field and search results should be hidden:
registrants.js
function toggle_caregiver_fields_on_ready(){
var caregiverSectionElement = $("#registrant_registration_attributes_registrant_id");
if ($("#registrant_registration_attributes_registered_as").val() === 'caregiver') {
$('.patient-caregiver-section').removeClass('hidden');
$('#patient-search-results').removeClass('hidden');
} else {
$('.patient-caregiver-section').addClass('hidden');
$('#patient-search-results').addClass('hidden');
}
}
In the same JS function I want to clear session[:patient_id_to_add_caregiver] when (#registrant_registration_attributes_registered_as").val() === 'caregiver'). I've tried with sessionStorage.clear(); to be:
if ($("#registrant_registration_attributes_registered_as").val() === 'caregiver') {
sessionStorage.clear();
$('.patient-caregiver-section').removeClass('hidden');
(...)
But nothing happened. Is it possible to clear this session storage?

NetSuite is entirely new to me and I'm trying to create a suitelet that needs to reflect my active roles. How shall I execute it in codes?

I know that there already is a 'View My Roles' under my account but I just need that page to reflect on a suitelet.
You will want to use the Suitelet Script Type, and methods available in the N/runtime Module (to get current user and role) and N/ui/serverWidget Module (to create the custom page). You can use methods in either the N/record Module or N/search Module (to gather user role data).
Here's a good start to how to outline your script. Once deployed as a Suitelet you will see a url provided. This will be the url to use to trigger the script. I do not know of a way to make the link attached to a Custom Center Tab, but minimally you can have users save the link to their NetSuite shortcuts, or browser shortcuts.
/**
* #NApiVersion 2.x
* #NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/runtime', 'N/record'], function(serverWidget, runtime, record) {
function onRequest(context){
if(context.request.method === 'GET'){ //GET is the request method when clicking on the url, POST or ELSE logic can be entered if you want to add for example a "submit button"
//create list w/2 columnms to display results in
var list = serverWidget.createList({
title: 'Available User Roles'
});
list.style = serverWidget.ListStyle.REPORT;
list.addColumn({
id: 'column1',
type: serverWidget.FieldType.TEXT,
label: 'Active Role?',
align: serverWidget.LayoutJustification.LEFT
});
list.addColumn({
id: 'column2',
type: serverWidget.FieldType.TEXT,
label: 'Role Name',
align: serverWidget.LayoutJustification.LEFT
});
//get current user role
var curUser = runtime.getCurrentUser(); //returns User (likely Employee) internal id
var curUserRoleId = curUserRole.role; //returns current role internal id
//empty array to keep all available roles
var availRoles = new Array();
//get all available roles using search or record module
//push each result to the array
availRoles.push(XXX);
//use ids to identify which result found above is the current role
var curRolePosition = availRoles.indexOf(curUserRoleId);
//add data to the list using addRow or addRows
//can also use a for loop for each result found when getting all available roles using search or record module
list.addRow({
row : { columnid1 : 'value1', columnid2 : 'value2' }
});
list.addRows({
rows : [{columnid1 : 'value1', columnid2 : 'value2'},
{columnid1 : 'value2', columnid2 : 'value3'}]
});
//display list to the user
context.response.writePage(list);
} else { //code that is exectuted i.e. after user presses "Submit button" (if created above in the GET area)
}
}
return {
onRequest: onRequest
}
});

How to do update in listing for web by using firebase

I am creating admin panel in website and I am using firebase as a database in backend.I am able to display listing but when I click on the particular listing there status should change from 'pending' to 'accept' but it doesnt.I dont know where I did mistake.Please give suggestion and I attach js file and database screenshot
pl.js
var firebaseheadingRef = firebase.database().ref().child("user");
firebaseheadingRef.on('child_added',datasnapshot=>{
var title= datasnapshot.child("listing").child("title").val();
var userid= datasnapshot.child("username").val();
var type= datasnapshot.child("listing").child("title").val();
var publisheddate= datasnapshot.child("listing").child("publish").val();
var expirydate= datasnapshot.child("listing").child("expire").val();
$("#tablebody").append("<tr><td>"+title+"</td><td>"+userid+"</td><td>"+type+"</td><td>"+publisheddate+"</td><td><button type=button id=accept onclick=accept()>Accept</button><button type=button>Reject</button></td></tr>");
});
function accept()
{
firebaseheadingRef.on('child_changed',datasnapshot=>{
datasnapshot.child("listing").child("status").update({"status":"accept"});
setCommentValues(postElement, data.key, data.val().text, data.val().author);
});
}
database
listing display picture where I click on accept button then update of status should done
There are two places where you need to change your code:
First, in the code that generates the table, you have to pass the id of the node to the function call, as follows. You get the node id with the key property of the DataSnapshot.
.....
$("#tablebody").append("<tr><td>"+title+"</td><td>"+userid+"</td><td>"+type+"</td><td>"+publisheddate+"</td><td><button type=button id=accept onclick=accept('" + datasnapshot.key + "')>Accept</button><button type=button>Reject</button></td></tr>");
...
And secondly you have to write your accept() function in such a way it updates the database value, with the set() method. Like the following
function accept(userId) {
var nodeRef = firebase.database().ref("/user/" + userId + "/listing/status");
return nodeRef.set('accept');
}

Pass Angular typeahead object result to another function in controller

In this scenario I'm using the ui-bootstrap typeahead to capture an object from an external api. Using the select callback I'm getting that object and have the results set in a separate function within my controller.
The issue is that I want to take those results and send them off to a separate api with a click function I already have set up. My question is how do i get the results of the type-ahead into the click function to post? The user flow is as follows.
<div>
<input type="text" placeholder="Find A Game"
typeahead-on-select="setGames($item)"
ng-model="asyncSelected"
typeahead="test.name for test in getGames($viewValue)"
typeahead-loading="loadingLocations" typeahead-min-length="3"
typeahead-wait-ms="500" typeahead-select-on-blur="true"
typeahead-no-results="noResults">
</div>
<div ng-show="noResults">
No Results Found
</div>
<button ng-disabled="!asyncSelected.length"
ng-click="addtodb(asyncSelected)">Add To Database</button>
As you can see the label is set to the items name and this works fine. When the user selects the name I then use typeahead-on-select="setGames($item)" to send off the entire object to its own funtion. From there I want to take the object and pass it to another function that you can see within the button tags ng-click. I currently have it passing the model, but what I really want is to pass the entire object within $item from the select event. So far my controller looks like this:
angular.module('2o2pNgApp')
.controller('GiantCtrl', function ($scope, $http, TermFactory, $window, SaveFactory) {
$scope.getGames = function(val) {
return $http.jsonp('http://www.example.com/api/search/?resources=game&api_key=s&format=jsonp&limit=5&json_callback=JSON_CALLBACK', {
params: {
query: val
}
}).then(function(response){
return response.data.results.map(function(item){
return item;
});
});
};
$scope.setGames = function (site) {
var newsite = site;
};
$scope.addtodb = function (asyncSelected, newsite) {
TermFactory.get({name: asyncSelected}, function(data){
var results = data.list;
if (results === undefined || results.length === 0) {
SaveFactory.save({vocabulary:'5', name:newsite.name, field_game_id:newsite.id}, function(data) {
$window.alert('All Set, we saved '+asyncSelected+' into our database for you!')
});
} else {
// do stuff
});
}
});
No matter what I do I cant seem to pass the entire $item object into this click function to post all the info i need.
Via New Dev in Comments:
$item is only available locally for typeahead-on-select... you can
either assign it to some model within your controller, or, in fact,
make the model of typeahead to be the item: typeahead="test as
test.name for test in getGames($viewValue)" – New Dev

Categories