Perform auto-search in ionic with MongoDB as backend - mongodb
The search should be based on the first name and last name. During entering the letters the middle letters from the word should not come. It should come only only from the first name and last name. I got the auto-complete code from code pen and Github but as per requirement I need auto search;
Like:
Auto Search
You should look at creating your own custom directive or using an existing one like this https://github.com/guylabs/ion-autocomplete
This is my code snippet for auto-complete which I used but I need First name and last name Search (It should not search random letters) -
var airlines = [{"fs":"LCI","iata":"LF","icao":"LCI","name":"Lao Central Airlines ","active":true},{"fs":"TGU","iata":"5U","icao":"TGU","name":"TAG","active":true},{"fs":"BT","iata":"BT","icao":"BTI","name":"Air Baltic","active":true},{"fs":"9J","iata":"9J","icao":"DAN","name":"Dana Airlines","active":true},{"fs":"2O","iata":"2O","icao":"RNE","name":"Island Air Service","active":true},{"fs":"NPT","icao":"NPT","name":"Atlantic Airlines","active":true},{"fs":"C8","iata":"C8","icao":"ICV","name":"Cargolux Italia","active":true},{"fs":"FK","iata":"FK","icao":"WTA","name":"Africa West","active":true},{"fs":"8K","iata":"8K","icao":"EVS","name":"EVAS Air Charters","active":true},{"fs":"W8","iata":"W8","icao":"CJT","name":"Cargojet","active":true},{"fs":"JBW","iata":"3J","icao":"JBW","name":"Jubba Airways (Kenya)","active":true},{"fs":"TNU","iata":"M8","icao":"TNU","name":"TransNusa","active":true},{"fs":"HCC","iata":"HC","icao":"HCC","name":"Holidays Czech Airlines","active":true},{"fs":"APJ","iata":"MM","icao":"APJ","name":"Peach Aviation","active":true},{"fs":"TUY","iata":"L4","icao":"TUY","name":"LTA","active":true},{"fs":"LAE","iata":"L7","icao":"LAE","name":"LANCO","active":true},{"fs":"L5*","iata":"L5","icao":"LTR","name":"Lufttransport","active":true},{"fs":"QA","iata":"QA","icao":"CIM","name":"Cimber","active":true},{"fs":"KBZ","iata":"K7","icao":"KBZ","name":"Air KBZ","active":true},{"fs":"L2","iata":"L2","icao":"LYC","name":"Lynden Air Cargo","active":true},{"fs":"MPK","iata":"I6","icao":"MPK","name":"Air Indus","active":true},{"fs":"CAO","icao":"CAO","name":"Air China Cargo ","active":true},{"fs":"BEK","iata":"Z9","icao":"BEK","name":"Bek Air","active":true},{"fs":"IAE","iata":"IO","icao":"IAE","name":"IrAero","active":true},{"fs":"GL*","iata":"GL","name":"Airglow Aviation Services","active":true},{"fs":"ATN","iata":"8C","icao":"ATN","name":"ATI","active":true},{"fs":"GU","iata":"GU","icao":"GUG","name":"Aviateca Guatemala","active":true},{"fs":"GHY","icao":"GHY","name":"German Sky Airlines ","active":true},{"fs":"SS","iata":"SS","icao":"CRL","name":"Corsair","active":true},{"fs":"XK","iata":"XK","icao":"CCM","name":"Air Corsica","active":true},{"fs":"W9*","iata":"W9","icao":"JAB","name":"Air Bagan","active":true},{"fs":"Z8*","iata":"Z8","icao":"AZN","name":"Amaszonas","active":true},{"fs":"D2","iata":"D2","icao":"SSF","name":"Severstal Aircompany","active":true},{"fs":"SNC","iata":"2Q","icao":"SNC","name":"Air Cargo Carriers","active":true},{"fs":"PST","iata":"7P","icao":"PST","name":"Air Panama","active":true},{"fs":"VV","iata":"VV","icao":"AEW","name":"Aerosvit Airlines","active":true},{"fs":"UJ","iata":"UJ","icao":"LMU","name":"AlMasria","active":true},{"fs":"9U","iata":"9U","icao":"MLD","name":"Air Moldova","active":true},{"fs":"NF","iata":"NF","icao":"AVN","name":"Air Vanuatu","phoneNumber":"678 238 48","active":true},{"fs":"NJS","iata":"NC","icao":"NJS","name":"Cobham Aviation","active":true}];
airlines = airlines.sort(function(a, b) {
var airlineA = a.name.to();
var airlineB = b.name.toLowerCase();
if(airlineA > airlineB) return 1;
if(airlineA < airlineB) return -1;
return 0;
});
console.log(airlines);
angular.module('ionicApp', ['ionic'])
.factory('FlightDataService', function($q, $timeout) {
var searchAirlines = function(searchFilter) {
console.log('Searching airlines for ' + searchFilter);
var deferred = $q.defer();
var matches = airlines.filter( function(airline) {
if(airline.name.toLowerCase().indexOf(searchFilter.toLowerCase()) !== -1 ) return true;
})
$timeout( function(){
deferred.resolve( matches );
}, 100);
return deferred.promise;
};
return {
searchAirlines : searchAirlines
}
})
.controller('MyCtrl', ['$scope', 'FlightDataService', function($scope, FlightDataService) {
$scope.myTitle = 'Auto Complete Example';
$scope.data = { "airlines" : [], "search" : '' };
$scope.search = function() {
FlightDataService.searchAirlines($scope.data.search).then(
function(matches) {
$scope.data.airlines = matches;
}
)
}
}]);
Related
Word web addin load whole document from server header/footer
We are trying to load a word document from server using JavaScript. We send the document using a base64 encoding. With our current approach, only the body is loading using the function: context.document.body.insertFileFromBase64(fileContent, "replace"); Unfortunately, the header and the footer are not loading. Is there another approach to load the whole document including body and footer?
the insertFile operation does not overwrite existing header/footers in the document.
According to my research, I saw this article for using insertFileFromBase64.The article says," if you use insertFileFromBase64 to insert the file it does have this blank page with header and footer." Did you have the same issue for this? However, another article says it's a design issue. Userform will encode data and will create an appointment on Microsoft Outlook Calendar The article provides approach: function getFile(){ Office.context.document.getFileAsync(Office.FileType.Compressed, { sliceSize: 4194304 /*64 KB*/ }, function (result) { if (result.status == "succeeded") { // If the getFileAsync call succeeded, then // result.value will return a valid File Object. var myFile = result.value; var sliceCount = myFile.sliceCount; var slicesReceived = 0, gotAllSlices = true, docdataSlices = []; console.log("File size:" + myFile.size + " #Slices: " + sliceCount); // Get the file slices. getSliceAsync(myFile, 0, sliceCount, gotAllSlices, docdataSlices, slicesReceived); } else { app.showNotification("Error:", result.error.message); } }); } function getSliceAsync(file, nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived) { file.getSliceAsync(nextSlice, function (sliceResult) { if (sliceResult.status == "succeeded") { if (!gotAllSlices) { // Failed to get all slices, no need to continue. return; } // Got one slice, store it in a temporary array. // (Or you can do something else, such as // send it to a third-party server.) docdataSlices[sliceResult.value.index] = sliceResult.value.data; if (++slicesReceived == sliceCount) { // All slices have been received. file.closeAsync(); onGotAllSlices(docdataSlices); } else { getSliceAsync(file, ++nextSlice, sliceCount, gotAllSlices, docdataSlices, slicesReceived); } } else { gotAllSlices = false; file.closeAsync(); console.log("getSliceAsync Error:", sliceResult.error.message); } }); } function onGotAllSlices(docdataSlices) { var docdata = []; for (var i = 0; i < docdataSlices.length; i++) { docdata = docdata.concat(docdataSlices[i]); } var fileContent = new String(); for (var j = 0; j < docdata.length; j++) { fileContent += String.fromCharCode(docdata[j]); } var mybase64 = window.btoa(fileContent); console.log("here is the base 64", mybase64); // Now all the file content is stored in 'fileContent' variable, // you can do something with it, such as print, fax... }
SAPUI5 oData POST 500 error
I'm trying to do a oData create on checkbox pressed and getting the following errors. Not sure if this is front end or a back end ABAP issue as have got this same function working in another project. It is failing on the create part but strangely is still passing through the details for SiteId, ArticleNumber, VarianceDate & Confirmed. // Set CheckBox status, X for true, blank for false onVarianceChecked: function (oEvent) { var oEntry = {}; var bindingContext = oEvent.getSource().getBindingContext(this.MODEL_VIEW); var path = bindingContext.getPath(); var object = bindingContext.getModel("SI").getProperty(path); // Pass in the Header fields oEntry.SiteId = this.SiteId; oEntry.ArticleNumber = object.ArticleNumber; oEntry.VarianceDate = moment(new Date(object.VarianceDate)).format('YYYY-MM-DDTHH:mm:ss'); // Set X or blank if (oEvent.getParameter("selected") === true) { oEntry.Confirmed = "X"; } else { oEntry.Confirmed = ""; } // Do the create var oModel = this.getView().getModel("SI"); oModel.create("/VarianceHeaderSet", oEntry, { success: function () { console.log("Variance confirmed"); MessageToast.show("Variance confirmed", { duration: 1000 }); }, error: function (oError) { console.log("Error, variance could not be confirmed"); MessageToast.show("Error, variance could not be confirmed", { duration: 1000 }); } }); }
'000000000' is the initial value for Edm.DateTime, hence it will fail when you have modelled a DateTime property to not be nullable. Go to SEGW and change the property to "nullable" or make sure that you always provide a correct Date in the POST.
global mongodb cursor in Meteor App
I'm trying to build an app with Meteor and I'm new to the framework. What I want to do is have the Mongocursor that get returned in the tablets functions with the search parameter to be used in colors functions. Currently in colors I'm just getting the reactive variable again and running the Tablets.find(). But I'm going to have many other functions like this so I want to use the same Mongo cursor. Is it possible to create a global Mongo cursor from the tablets functions that will also be reactive. The code below is my setup: Template.tabletsList.helpers({ tablets: function() { // read the user's last search (if any) var query = Template.instance().query.get(); // sort options var options = {sort: {manufacturer: 1}}; if ($.isEmptyObject(query)) { // if the user didn't input a search just find all tablets var tabletCursor = Tablets.find({}, options); return tabletCursor; } else { // find all tablets matching the search expression return Tablets.find(query, options); } }, colors: function() { var query = Template.instance().query.get(); if ($.isEmptyObject(query)) var allTablets = Tablets.find().fetch(); else var allTablets = Tablets.find(query).fetch(); var color = ''; var colors = []; allTablets.forEach(function (tablet) { for (var i=0; i<tablet.specs.color.length; i++) { color = tablet.specs.color[i]; if ($.inArray(color, colors) === -1) { colors.push(color); } } }); return colors.sort(); }
You can create a global helper: Template.registerHelper('tablets',function(query){ var options = {sort: {manufacturer: 1}}; if ($.isEmptyObject(query)) query = {}; return = Tablets.find(query, options); }); Then from anywhere in your code you can access this with: var tabletCursor = UI._globalHelpers.tablets(query); If you don't have access to query everwhere you can add it to Session or create a new reactive variable to hold it.
CoffeeScript code-complete for Web IDE
Is there a web based code-complete API/IDE for coffee script? Ace Editor and CodeMirror have good syntax highlighting and lint-based syntax support, and what I would like to add to my app (Node-WebKit-REPL) is code-complete support
Unfortunately neither CodeMirror nor Ace have autocompleters specially for coffeescript, but they both have an api to add a completer. here's a simple example to show how do it for ace var lang = require("ace/lib/lang") var languageTools = require("ace/ext/language_tools") editor = ace.edit("editor") editor.setOptions({ enableBasicAutocompletion: true, enableLiveAutocompletion: true, // this does not work very well atm mode: "ace/mode/coffee" }) var evalCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { var completions = []; var props = Object.keys(window); props.forEach(function(key){ completions.push({ value: key, meta: 'window', type: 'eval', score: 1000 }); }) callback(null, completions) }, getDocTooltip: function(item) { if (item.type == 'eval' && !item.docHTML) { var o = window[item.value] var type = typeof o item.docHTML = "<b>" + type + "</b><br>" + lang.escapeHTML(o + ""); } } } editor.completers = [evalCompleter, languageTools.keyWordCompleter, languageTools.snippetCompleter, languageTools.textCompleter ]; of course in a real application you will need some kind of parser to get the expression before the . to evaluate http://sevin7676.github.io/Ace.Tern/demo.html also can be useful.
How to Delete Facebook Messages via Facebook API?
Is there a way to retrieve all Facebook Message ids with the read mailbox permission and then delete them all one by one? Everyone is crying about how it's difficult to delete your chat/message history. I wondered if there was an easy way to write an app to do this. Facebook API - Message
Normally you would issue an HTTP DELETE call to https://graph.facebook.com/messageID?access_token=... But it appears that this is an API call that either require special whitelisting from Facebook or isn't currently supported because it does not work right now and returns "Unsupported delete request."
Install https://chrome.google.com/webstore/detail/jquerify/gbmifchmngifmadobkcpijhhldeeelkc Open the facebook using https://mbasic.facebook.com/messages/?_rdr Enable jQuery using jQueryify extension you installed. Then go to your chrome developer tools> sources > snippet and create a new snippet and paste the following code and run it. // Code snippet for facebook messages removing: var WHITELISTED_USERS_X = []; function removeElement(elementId) { // Removes an element from the document var element = document.getElementById(elementId); if (element) { element.parentNode.removeChild(element); } } function addElement(parentId, elementTag, elementId, html) { // Adds an element to the document // removeElement removeElement(elementId); var p = document.getElementById(parentId); var newElement = document.createElement(elementTag); newElement.setAttribute('id', elementId); newElement.innerHTML = html; if (p) { p.appendChild(newElement); } else { var body = document.getElementsByTagName("body")[0] body.appendChild(newElement); } } addElement("body", "div", "123x", "hello World23"); console.log(`getOlderMessagesLink()`); console.log(getOlderMessagesLink()); var aLinks = document.querySelectorAll('h3 a'), i; for (i = 0; i < aLinks.length; ++i) { let currentLink = aLinks[i]; currentLink.style.color = currentLink.style.color == "black" ? "red" : "green"; $.get( currentLink.href, function( data ) { getPayload1(currentLink.href).then(payLoad=>{ let abLink = currentLink.href; let deleteApiLink = abLink.split('?').pop().split('&'); deleteApiLink.splice(1 , 0, `tids=${deleteApiLink[0].split('=').pop()}`) deleteApiLink = deleteApiLink.join("&").split("#").shift(); const apiLink = `https://mbasic.facebook.com/messages/action_redirect?` + deleteApiLink; $.post(apiLink, payLoad ).done(function( data ) { let mydeletehref = findInParsed(data, "a:contains('Delete')"); const username = currentLink.innerText; const deleteLink = mydeletehref.href; if(WHITELISTED_USERS_X.indexOf(username) == -1){ // console.log(`${username}: ${deleteLink}`); insertDeleteLinkInUser(username, deleteLink); } }); }); }) } function getPayload1(link){ return new Promise(resp=>{ $.get(link, function( html1 ) { let fbDtsg = findInParsed(html1, "input[name='fb_dtsg']"); let jazoest = findInParsed(html1, "input[name='jazoest']"); resp ({ "fb_dtsg": fbDtsg.value, "jazoest": jazoest.value, "delete": "Delete" }) }); }) } function findInParsed(html, selector){ return $(selector, html).get(0) || $(html).filter(selector).get(0); } function getOlderMessagesLink(html = false){ if(html){ return $("#see_older_threads").find("a").get(0).href; } let selector = "#see_older_threads"; return $(selector, html).find("a").get(0).href || $(html).filter(selector).find("a").get(0).href; } function insertDeleteLinkInUser(username, link){ $("a:contains('" + username + "')").parent().parent().parent().prepend('DELETE ME'); }