Sorter Function in List never called - qooxdoo

I tried to Implement the qx.ui.list.core.IListDelegate.sorter function in a qx.data.controller.List. I set the Delegate of the controller with the specific sort Function. The Problem is, that the sorter Function is never been called.
var list = new qx.ui.form.List();
var rawData = [];
for (var i = 0; i < 10; i++) {
rawData.push(i);
}
var data = new qx.data.Array(rawData);
var listController = new qx.data.controller.List(data, list);
listController.setDelegate({
sorter : function(a, b) {
console.log("test");
if (Number(a.getLabel()) > Number(b.getLabel())) {
return 1;
}
if (Number(a.getLabel()) < Number(b.getLabel())) {
return -1;
}
return 0;
}
});
// Document is the application root
var doc = this.getRoot();
doc.add(list,
{
left : 100,
top : 50
});
Here is the example in the qx Playground: tinyurl.com/y6udac8g

qx.ui.list.core.IListDelegate.sorter is used to configure qx.ui.list.List and not qx.ui.form.List.
Check the example in the documentation to use the sorter function of the qx.ui.list.List class
//create the model data
var rawData = [];
for (var i = 0; i < 2500; i++) {
rawData[i] = "Item No " + i;
}
var model = qx.data.marshal.Json.createModel(rawData);
//create the list
var list = new qx.ui.list.List(model);
//configure the lists's behavior
var delegate = {
sorter : function(a, b) {
return a > b ? 1 : a < b ? -1 : 0;
}
};
list.setDelegate(delegate);
//Pre-Select "Item No 20"
list.getSelection().push(model.getItem(20));
//log selection changes
list.getSelection().addListener("change", function(e) {
this.debug("Selection: " + list.getSelection().getItem(0));
}, this);

Related

Get element in Array

In the execution of my code, how do I get the r.diameter element, which is stored in an array, to another code function?
public static RebarProps [] GetRebarsHor (Element el, Document doc)
{
var rebars = RebarHostData.GetRebarHostData(el).GetRebarsInHost();
var rlst = new List<RebarProps>();
var klen = RevitUnits.ConvertToDisplayUnitsLength(doc);
foreach (var rebar in rebars)
{
if (IsHor(rebar, out var numesegs, out var segment))
{
var r = new RebarProps();
r.diameter = GetRebarDiameter (rebar) * klen;
r.spacing = rebar.MaxSpacing * klen;
r.isStirrup = numesegs > 1;
rlst.Add(r);
}
}
return rlst.ToArray();
}
public static double GetConfinedWidth (Element el, Document doc)
{
var array = GetRebarsHor (el, doc);
foreach( var item in array)
{
}
}
Thanks!
I would assume item.diameter.

Script not running thru all iterations, and getting stuck in a loop

I have a script that is working. It is to loop thru a number of different spreadsheets, and make the same edits in each. The edits are: Adding 2 formulas, conditional formatting a cell, and removing protection from 6 sheets. But there seems to be an issue with the first 'FOR' loop. It is only doing 2 iterations, then keeps running. I have had to force stop each of my attempts after several minutes. I am fairly new, so I think the issue may be with my syntax and brackets {}.
var sheetIds = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Blueprints"); //Change as needed -DONE
var values = sheetIds.getRange('j19:j96').getValues(); //Change to proper range -DONE j3:j96
var idList = values.map(function (row) {
return row[0];
}).filter(function (id) {
return id;
});
for (var i = 0; i < idList.length; i++) {
// var form1 = "Roster!A1"
// var form2 = "KPI!A1"
var s = SpreadsheetApp.openById(idList[i]);
var ss = s.getSheetByName('Blueprint');
var roster = ss.getRange('e3');
var kpi = ss.getRange('f3');
var form1 = "Roster!A1"
var form2 = "KPI!A1"
roster.setFormula(form1)
kpi.setFormula(form2)
//var range = ss.getRange('t1')
var rule = SpreadsheetApp.newConditionalFormatRule()
.whenTextContains('Advocates')
.setFontColor('#c9daf8')
.setRanges([roster])
.build();
var rules = ss.getConditionalFormatRules();
rules.push(rule);
ss.setConditionalFormatRules(rules);
//var s = SpreadsheetApp.getActiveSpreadsheet();
var store = s.getSheetByName('Store');
var prot = store.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot.length; i++) {
var protection = prot[i];
if (protection.canEdit()) {
protection.remove();
}
}
var adv1 = s.getSheetByName('Advocate1');
var prot1 = adv1.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot1.length; i++) {
var protection1 = prot1[i];
if (protection1.canEdit()) {
protection1.remove();
}
}
var adv2 = s.getSheetByName('Advocate2');
var prot2 = adv2.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot2.length; i++) {
var protection2 = prot2[i];
if (protection2.canEdit()) {
protection2.remove();
}
}
var adv3 = s.getSheetByName('Advocate3');
var prot3 = adv3.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot3.length; i++) {
var protection3 = prot3[i];
if (protection3.canEdit()) {
protection3.remove();
}
}
var adv4 = s.getSheetByName('Advocate4');
var prot4 = adv4.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot4.length; i++) {
var protection4 = prot4[i];
if (protection4.canEdit()) {
protection4.remove();
}
}
var adv5 = s.getSheetByName('Advocate5');
var prot5 = adv5.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var i = 0; i < prot5.length; i++) {
var protection5 = prot5[i];
if (protection5.canEdit()) {
protection5.remove();
}
}
}
}
It would be a massive time saver if I could figure this out!!!
Try this:
I just replaced all of the inner loop indices with j
function myFunction() {
var sheetIds=SpreadsheetApp.getActive.getSheetByName("Blueprints");
var values=sheetIds.getRange('j19:j96').getValues();
var idList=values.map(function (row) {return row[0];}).filter(function (id) {return id;});
for (var i=0;i<idList.length;i++) {
var s=SpreadsheetApp.openById(idList[i]);
var ss=s.getSheetByName('Blueprint');
var roster=ss.getRange('e3');
var kpi=ss.getRange('f3');
var form1="Roster!A1";
var form2="KPI!A1";
roster.setFormula(form1);
kpi.setFormula(form2);
var rule=SpreadsheetApp.newConditionalFormatRule().whenTextContains('Advocates').setFontColor('#c9daf8').setRanges([roster]).build();
var rules=ss.getConditionalFormatRules();
rules.push(rule);
ss.setConditionalFormatRules(rules);
var store=s.getSheetByName('Store');
var prot=store.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for(var j=0;j<prot.length; j++) {
var protection=prot[j];
if (protection.canEdit()) {
protection.remove();
}
}
var adv1=s.getSheetByName('Advocate1');
var prot1=adv1.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var j=0; j < prot1.length; j++) {
var protection1=prot1[j];
if (protection1.canEdit()) {
protection1.remove();
}
}
var adv2=s.getSheetByName('Advocate2');
var prot2=adv2.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var j=0; j < prot2.length; j++) {
var protection2=prot2[j];
if (protection2.canEdit()) {
protection2.remove();
}
}
var adv3=s.getSheetByName('Advocate3');
var prot3=adv3.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var j=0; j < prot3.length; j++) {
var protection3=prot3[j];
if (protection3.canEdit()) {
protection3.remove();
}
}
var adv4=s.getSheetByName('Advocate4');
var prot4=adv4.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var j=0; j < prot4.length; j++) {
var protection4=prot4[j];
if (protection4.canEdit()) {
protection4.remove();
}
}
var adv5=s.getSheetByName('Advocate5');
var prot5=adv5.getProtections(SpreadsheetApp.ProtectionType.SHEET)
for (var j=0; j < prot5.length; j++) {
var protection5=prot5[j];
if (protection5.canEdit()) {
protection5.remove();
}
}
}
}

AngularJS : why is searching not working properly?

I am trying to search text on table using angular ..I am able to search text in table .But my search works when I press enter or “search button” .Example when I write “Active” it not show the result but when I press enter or press search button it show the output .can we do the like search like autocomplete .Example when I press “a’ it show all item which start from “a” .Then if user write “ac” then show “ac” value ..same like that .when user write “active “ it show rows which have “active” without using search button or enter .can we make add filter so that it works properly ?
here is my code
$scope.searchInvoices = function(evt, queryval) {
$scope.haveNorecordFound = true;
if (typeof queryval != "undefined" && queryval.length === 0 || evt.keyCode === 13 || evt.type === 'click') {
if (typeof queryval == "undefined" || queryval.length === 0) {
console.log("if===")
isfilterOccured = false;
$scope.tasklist_records = $scope.total_tasklist_records;
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
} else {
console.log("esle===")
var recordset = $scope.serachObject;
results = [];
var recordsetLength = recordset.length;
var searchVal = queryval.toLowerCase();
var i, j;
for (i = 0; i < recordsetLength; i++) {
var record = recordset[i].columns;
for (j = 0; j < record.length; j++) {
if (record[j].value != null) {
var invoice = record[j].value.toLowerCase();
if (invoice.indexOf(searchVal) >= 0) {
results.push(recordset[i]);
}
}
}
}
var nameOrPathValues = results.map(function(o) {
var result = {};
o.columns.forEach(function(c) {
result[c.fieldNameOrPath] = c.value;
});
return result;
});
console.log("serach");
console.log(nameOrPathValues);
var objectarray = nameOrPathValues.map(function(o) {
var result = {};
collectNameOrPath.forEach(function(name) {
result[name] = o[name];
});
return result;
});
isfilterOccured = true;
$scope.tasklist_records = objectarray;
if ($scope.tasklist_records.length == 0) {
$scope.haveNorecordFound = false;
} else {
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
}
}
}
};
After debugging in code, I found that you're biding function on either enter button press or search click. That's why it was not working on ng-keyup. Please replace your function from below code.
$scope.searchInvoices = function(evt, queryval) {
console.log(queryval)
$scope.haveNorecordFound = true;
var recordset = $scope.serachObject;
results = [];
var recordsetLength = recordset.length;
var searchVal = queryval.toLowerCase();
var i, j;
for (i = 0; i < recordsetLength; i++) {
var record = recordset[i].columns;
for (j = 0; j < record.length; j++) {
if (record[j].value != null) {
var invoice = record[j].value.toLowerCase();
if (invoice.indexOf(searchVal) >= 0) {
results.push(recordset[i]);
}
}
}
}
var nameOrPathValues = results.map(function(o) {
var result = {};
o.columns.forEach(function(c) {
result[c.fieldNameOrPath] = c.value;
});
return result;
});
console.log("serach");
console.log(nameOrPathValues);
var objectarray = nameOrPathValues.map(function(o) {
var result = {};
collectNameOrPath.forEach(function(name) {
result[name] = o[name];
});
return result;
});
isfilterOccured = true;
$scope.tasklist_records = objectarray;
if ($scope.tasklist_records.length == 0) {
$scope.haveNorecordFound = false;
} else {
$scope.totalNumberOfrecord = $scope.tasklist_records.length + " records found."
}
};

For each string in Array

Just as the name says, I want that for each certain name in an array a value is added to a int.
For example: if there are 3 strings of the same name in the array, then 3 times 50 will be added to the value.
This is my script I have now:
var lootList = new Array();
var interaction : Texture;
var interact = false;
var position : Rect;
var ching : AudioClip;
var lootPrice = 0;
function Update()
{
print(lootList);
if ("chalice" in lootList){
lootPrice += 50;
}
}
function Start()
{
position = Rect( ( Screen.width - interaction.width ) /2, ( Screen.height - interaction.height ) /2, interaction.width, interaction.height );
}
function OnTriggerStay(col : Collider)
{
if(col.gameObject.tag == "loot")
{
interact = true;
if(Input.GetKeyDown("e"))
{
if(col.gameObject.name == "chalice")
{
Destroy(col.gameObject);
print("chaliceObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("chalice");
}
if(col.gameObject.name == "moneyPouch")
{
Destroy(col.gameObject);
print("moneyPouchObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("moneyPouch");
}
if(col.gameObject.name == "ring")
{
Destroy(col.gameObject);
print("ringObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("ring");
}
if(col.gameObject.name == "goldCoins")
{
Destroy(col.gameObject);
print("coldCoinsObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("goldCoins");
}
if(col.gameObject.name == "plate")
{
Destroy(col.gameObject);
print("plateObtained");
audio.clip = ching;
audio.pitch = Random.Range(0.8,1.2);
audio.Play();
interact = false;
lootList.Add("plate");
}
}
}
}
function OnTriggerExit(col : Collider)
{
if(col.gameObject.tag == "pouch")
{
interact = false;
}
}
function OnGUI()
{
if(interact == true)
{
GUI.DrawTexture(position, interaction);
GUI.color.a = 1;
}
}
It's for a game I'm making where you can steal items for extra score points.
I've tried using the for(i = 0; i < variable.Length; i++) but that didn't seem to work.
The only thing I can think of now is using booleans to add it once. But that isn't memory friendly.
Help is appreciated and thanks in advance!
You could use the standard .forEach(callback) method:
lootList.forEach(function(value, index, array)
{
if (value === "chalice") { lootPrice += 50; }
});
If you don't have that method, you could implement it like this:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (callback) {
for(var i = 0; i < this.length; i++) { callback(this[i], i, this); }
}
}

Sorting an array to avoid neighboring items having duplicate attributes

I have an array of objects. Each object has a color attribute which could be "red", "blue", "yellow", "green", "orange" or "purple". There are 20-30 objects in the array so colors repeat. My goal is to sort the array so that no colors are next to each other. Distribution of colors is not exactly even but close.
This is what I have so far. It checks the next and previous object for a color match and if it finds a match it moves it to the end of the array.
private function sortColors():void
{
var getNext:uint;
var getPrev:uint;
var maxCount:uint = colorArray.length;
for (var i:uint = 0; i < maxCount; i++) {
var cur:ValueObject = colorArray[i];
(i == maxCount-1) ? getNext = 0 : getNext = i+1;
(i == 0) ? getPrev = maxCount-1 : getPrev = i-1;
var next:ValueObject = colorArray[getNext];
var prev:ValueObject = colorArray[getPrev];
if (cur.color == next.color) {
var move:ValueObject = colorArray[getNext];
colorArray.splice(getNext, 1);
colorArray.push(move);
}
if (cur.color == prev.color) {
var move:ValueObject = colorArray[getPrev];
colorArray.splice(getPrev, 1);
colorArray.push(move);
}
}
}
This works OK but if there is more of a certain color they end up repeating at the end. I could add something to the end to throw those back into the mix but I feel like there must be a better way. Someone enlighten me.
Try:
var colorObjects:Array = [/* list of objects with colors - populated below*/];
var jumbled:Array = [];
var lastColor:String = "";
function getDifferentTile():void
{
if(lastColor.length == 0)
{
jumbled.push(colorObjects.pop());
lastColor = jumbled[0].mycolor;
}
else
{
var i:Object;
for each(i in colorObjects)
{
var repeat:uint = 0;
if(i.mycolor != lastColor)
{
jumbled.push(i);
lastColor = i.mycolor;
colorObjects.splice(colorObjects.indexOf(i), 1);
return;
} else {
repeat++;
}
if (repeat > 0 && repeat == colorObjects.length) {
jumbled.push(i);
colorObjects.splice(colorObjects.indexOf(i), 1);
return;
}
}
}
}
// list of random colors
var colors:Array = ["0x000000","0x444444","0xFFFFFF","0xFF00FF"];
// prepare random array for test
var i:uint = 0;
for(i; i<100; i++)
{
var obj:Object =
{
mycolor: colors[uint(Math.random()*colors.length)]
};
colorObjects.push(obj);
}
// fill the jumble array until the original listing is empty
while(colorObjects.length > 0)
{
getDifferentTile();
}
// output jumbled
var j:Object;
for each(j in jumbled)
{
trace(j.mycolor);
}

Resources