Save and Load Data Model in Sench Touch 2.1 - sencha-touch-2

Everybody!
I need to read and write a history data array.My data does loose data while page refresh. Thanks!

I resolved this problem by using LocalStore HTML 5.
With a some simple data, you can use:
var data = {};// data is a object just include text and value.
data = {"key1": value1, "key2": value2};// Example, i have a this object.
//===> We save a object "history" by a string of "data" var.
localStorage.setItem('history', JSON.stringify(data));
// ===> And get it:
var retrievedHistory = localStorage.getItem('history');
// In Sencha Touch, you can parse this oject to your model. and Syns it.
var history = Ext.getStore("HistoryTracking");
history.removeAll();
var num = Object.keys(data).length;
for (i = 0; i < num; i++)
{
var string = '' + data["trackID" + i];
history.add(string);
}
history.sync();
Hope my sharing help you have same problem!

Related

Talend Open Studio 7.1 : tJavaFlex output issue

I'm asking for your help,I'm facing a problem with the tJavaFlex component.
editorName ;ProductName ;end_date_resorption_versions;end_date_supported_versions ;end_date_recommended_versions
EditorA;PN_A;31/03/2017,31/03/2017,31/03/2017,31/03/2017,31/03/2017,31/03/2017;null;null
EditorA;PN_A;30/06/2024;null;30/06/2024
EditorA;PN_A;30/11/2020,30/06/2017;null;null
EditorA;PN_A;null;30/06/2024;null
EditorA;PN_A ;null;null;null
EditorA;PN_A;30/11/2020,30/11/2020;null;null
EditorB;PN_B;18/05/2017,31/03/2017,31/01/20;null;null
EditorB;PN_B;03/06/2024;01/02/2020;30/06/2024
EditorB;PN_B;23/12/2014 ;null;null
EditorB;PN_B;null;01/02/2020;30/06/2020
EditorB;PN_B;null;null;null
EditorB;PN_B;12/12/2012,31/12/2020;null;13/01/2020
As u can see there are list of date (string format) in same column.
What i want to do ==> it's to find the min date for each column (not row)
My approach is this :
By column, store all values in an array
convert ListString to ListDate
Find Date min in each ListDate
I thought the best way to do that was to use the tJavaFlex component.
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**Start Code :**
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
// Array for end_date_resorption_versions
List<String> myStringList_edrv = new ArrayList<>();
List<Date> dates = new ArrayList<>();
// Array for end_date_supported_versions
List<String> myStringList_edsv = new ArrayList<>();
List<Date> dates_edsv = new ArrayList<>();
// Array for end_date_recommended_versions
List<String> myStringList_edrev = new ArrayList<>();
List<Date> dates_edrev = new ArrayList<>();
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**main code :**
if (row4.end_date_resorption_versions == null ){
row4.end_date_resorption_versions = "31/12/2099";
}
if (row4.end_date_supported_versions == null ){
row4.end_date_supported_versions = "31/12/2099";
}
if (row4.end_date_recommended_versions == null) {
row4.end_date_recommended_versions = "31/12/2099";
}
// populating data :
myStringList_edrv.addAll(Arrays.asList(row4.end_date_resorption_versions.split(",")));
myStringList_edsv.addAll(Arrays.asList(row4.end_date_supported_versions.split(",")));
myStringList_edrev.addAll(Arrays.asList(row4.end_date_recommended_versions.split(",")));
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
**end code :**
// transform ListString to ListDate : end_date_resorption_versions
for (int i = 0 ; i < myStringList_edrv.size(); i++) {
dates.add(sdf.parse(myStringList_edrv.get(i)));
}
// transform ListString to ListDate : end_date_supported_versions
for (int i = 0 ; i < myStringList_edsv.size(); i++) {
dates_edsv.add(sdf.parse(myStringList_edsv.get(i)));
}
// transform ListString to ListDate : end_date_recommended_versions
for (int i = 0 ; i < myStringList_edrev.size(); i++) {
dates_edrev.add(sdf.parse(myStringList_edrev.get(i)));
}
// getMinDate : end_date_resorption_versions
row6.out_date_edrv = sdf.format(Collections.min(dates));
// getMinDate : end_date_supported_versions
row6.out_date_edsv = sdf.format(Collections.min(dates_edsv));
// getMinDate : end_date_recommended_versions
row6.out_date_edrev = sdf.format(Collections.min(dates_edrev));
row6.out_editor_name = row4.editor_name;
row6.out_product_name = row4.product_name;
System.out.println("out_date_edrv => " + row6.out_date_edrv);
System.out.println("out_date_edsv => " + row6.out_date_edsv);
System.out.println("out_date_edrev => " + row6.out_date_edrev);
all my values are null, while the results present in the system.out.println are good
my job design is :
tPostgresqlInput----row4(Main)----tJavaFlex_1----row6(Main)----tLogRow
some help would really be appreciated.
You don't need all that java code. Here's a solution using only Talend components which has the advantage of being easier to maintain should your requirement change.
I start by normalizing your date columns; if only end_date_resorption_versions can contain a list of dates, then you can skip tNormalize_2 and tNormalize_3 which normalize end_date_supported_versions and end_date_recommended_versions respectively.
the tMap_1 is probably not needed, I use it to convert the "null" literal to null, since I copy pasted your sample data in a file for my test, otherwise the following conversion would fail.
tConvertType_1 then converts the date string to Date type, by checking the option "Auto cast", and setting the schema as follows:
Finally, tAggregateRow_1 will group on the editorName and ProductName columns and get the minimum date from each date column:
No explanation, just a nasty hack : Try to insert a tFlowToIterate before your tJavaFlex and feed the tJavaFlex with an iterate flow instead of a main flow (See pictures below).
Here, for some reason my tJavaFlex only reads null values from the input main flow
But it manages to read the exact same data when provided through an iterate flow.
Note that as long as your input data flow isn't renamed (row4 in my example), you won't have to touch the code in your tJavaFlex.
I have absolutely no clue on why nor when tJavaFlex wouldn't cope well with flows of type main, and I find that rather frustrating. I would surely appreciate if a talend guru could give me an explanation !

Get the value of selectbox in cocoascript

I'm developing a sketch plugin. In the modal window I'm using to get user input there is a select. I can access the value of textField but I can't access value of the select.
Here is where I create the select:
var chooseFormatOptions = ['.png', '.jpg', '.pdf'];
var chooseFormatSelect = NSComboBox.alloc().initWithFrame(NSMakeRect(0, 250, viewWidth, 30));
chooseFormatSelect.addItemsWithObjectValues(chooseFormatOptions);
Here is where I try to get the combo box value
if (response == "1000"){
var projectName = projectField.stringValue();
var deviceName1 = firstDevicefield.stringValue();
var deviceDim1 = firstDimfield.stringValue();
var deviceName2 = secondDevicefield.stringValue();
var deviceDim2 = secondDimfield.stringValue();
var format = chooseFormatSelect.objectValues.indexOfSelectedItem(),
//var scale = chooseScaleOptions.stringValue();
//var pathOption = choosePathOptions.stringValue();
}
The error that it gives me when I run the plugin (if response == 1000) is: can't find variable chooseFormatSelect.
Do you know why I can get values of input fields (so it can find variables) but not that of the select one?
What about access text field 'text' variable while observing changes?
You may find this link helpfull (to add observe).
For NSComboBox follow this
Simply implement delegate then access value through following method

dynamically change a part of the variable path

I know this question has been asked a bunch of times, but none of the answers (or at least what i took away from them) was a help to my particiular problem.
I want to dynamically change a part of the variable path, so i don't have to repeat the same code x-times with just two characters changing.
Here's what i got:
In the beginning of my script, i'm setting the reference to PlayerData scripts, attached to the GameManager object like this:
var P1 : P1_Data;
var P2 : P2_Data;
function Start(){
P1 = GameObject.Find("GameManager").GetComponent.<P1_Data>();
P2 = GameObject.Find("GameManager").GetComponent.<P2_Data>();
}
Later, i want to access these scripts using the currentPlayer variable to dynamically adjust the path:
var currentPlayer : String = "P1"; //this actually happens along with some other stuff in the SwitchPlayers function, i just put it here for better understanding
if (currentPlayer.PlayerEnergy >= value){
// do stuff
}
As i was afraid, i got an error saying, that PlayerEnergy was not a part of UnityEngine.String.
So how do I get unity to read "currentPlayer" as part of the variable path?
Maybe some parse function I haven't found?
Or am I going down an entirely wrong road here?
Cheers
PS: I also tried putting the P1 and P2 variables into an array and access them like this:
if (PlayerData[CurrentPlayerInt].PlayerEnergy >= value){
// do stuff
}
to no success.
First of all,
var currentPlayer : String = "P1"
here P1 is just string, not the previous P1/P2 which are referenced to two scripts. So, if you want, you can change
currentPlayer.PlayerEnergy >= value
to
P1.PlayerEnergy >= value
or,
P2.PlayerEnergy >= value
But if you just want one function for them, like
currentPlayer.PlayerEnergy >= value
Then you have to first set currentPlayer to P1/P2 which I assume you are trying to do. You must have some codes that can verify which player is selected. Then, maybe this can help -
var playerSelected: int = 0;
var currentPlayerEnergy: int = 0;
.....
//Use your codes to verify which player is selected and then,
if (playerSelected == 1) {
currentPlayerEnergy = P1.PlayerEnergy;
} else if (playerSelected == 2) {
currentPlayerEnergy = P2.PlayerEnergy;
}
//Now use your favorite function
if (currentPlayerEnergy >= value) {
//Do stuff
}
As there was no reply providing the answer I needed, I'll share the solution that did the trick for me, provided by a fellow student.
Instead of having the PlayerData scripts pre-written, I generate them using a public class function in a Playermanager script. This generates the Playerdata as attached scripts, saved into an array.
I can then access them through Playermanager.Playerlist[Playernumber].targetvariable.
Which is what I wanted to do, only with the Playerdata being attached to a script instead of a gameobject. And it works great!
Here's the full code of my Playermanager Script:
//initialise max players
public var maxplayers : int = 2;
// Initialise Playerlist
static var Players = new List.<PlayerData>();
function Start () {
for (var i : int = 0; i < maxplayers; i++){
var Player = new PlayerData();
Players.Add(Player);
Players[i].PlayerName = "Player " + i;
}
DontDestroyOnLoad (transform.gameObject);
}
public class PlayerData {
public var PlayerName : String;
public var PlayerEnergy : int = 15;
public var Fleet : List.<GameObject> = new List.<GameObject>();
}
As you see, you can put any type of variable in this class.
I hope this helps some of you who have the same problem.
cheers,
Tux

how to use serialization package

I want to convert my class to a Map so I'm using Serialization package. From the example it looks simple:
var address = new Address();
address.street = 'N 34th';
address.city = 'Seattle';
var serialization = new Serialization()
..addRuleFor(Address);
Map output = serialization.write(address);
I expect to see an output like {'street' : 'N 34th', 'city' : 'Seattle'} but instead it just output something I-don't-know-what-that-is
{"roots":[{"__Ref":true,"rule":3,"object":0}],"data":[[],[],[],[["Seattle","N 34th"]]],"rules":"{\"roots\":[{\"__Ref\":true,\"rule\":1,\"object\":0}],\"data\":[[],[[{\"__Ref\":true,\"rule\":4,\"object\":0},{\"__Ref\":true,\"rule\":3,\"object\":0},{\"__Ref\":true,\"rule\":5,\"object\":0},{\"__Ref\":true,\"rule\":6,\"object\":0}]],[[],[],[\"city\",\"street\"]],[[]],[[]],[[]],[[{\"__Ref\":true,\"rule\":2,\"object\":0},{\"__Ref\":true,\"rule\":2,\"object\":1},\"\",{\"__Ref\":true,\"rule\":2,\"object\":2},{\"__Ref\":true,\"rule\":7,\"object\":0}]],[\"Address\"]],\"rules\":null}"}
Serialization is not supposed to create human-readable output. Maybe JSON output is more what you look for:
import dart:convert;
{
var address = new Address();
..address.street = 'N 34th';
..address.city = 'Seattle';
var encoded = JSON.encode(address, mirrorJson);
}
Map mirrorJson(o) {
Map map = new Map();
InstanceMirror im = reflect(o);
ClassMirror cm = im.type;
var decls = cm.declarations.values.where((dm) => dm is VariableMirror);
decls.forEach((dm) {
var key = MirrorSystem.getName(dm.simpleName);
var val = im.getField(dm.simpleName).reflectee;
map[key] = val;
});
return map;
}
The new Address() creates a full prototype object which is what you are seeing. That being said, they could have done something to avoid part of those, but if you want to restore the object just the way it is, that's necessary.
To see the full content of an object you use the for() instruction in this way:
for(obj in idx) alert(obj[idx]);
You'll see that you get loads of data this way. Without the new Address() it would probably not be that bad.
Serialization won't help you here...
You might give a try to JsonObject library, and maybe go through this in depth explanation how to do what you are trying to do using mirrors.

Conditionally adjust visible columns in Rally Cardboard UI

So I want to allow the user to conditionally turn columns on/off in a Cardboard app I built. I have two problems.
I tried using the 'columns' attribute in the config but I can't seem to find a default value for it that would allow ALL columns to display(All check boxes checked) based on the attribute, ie. the default behavior if I don't include 'columns' in the config object at all (tried null, [] but that displays NO columns).
So that gets to my second problem, if there is no default value is there a simple way to only change that value in the config object or do I have to encapsulate the entire variable in 'if-else' statements?
Finally if I have to manually build the string I need to parse the values of an existing custom attribute (a drop list) we have on the portfolio object. I can't seem to get the rally.forEach loop syntax right. Does someone have a simple example?
Thanks
Dax - Autodesk
I found a example in the online SDK from Rally that I could modify to answer the second part (This assumes a custom attribute on Portfolio item called "ADSK Kanban State" and will output values to console) :
var showAttributeValues = function(results) {
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
console.log("Attribute Value : " + results[property][i]);
}
}
};
var queryConfig = [];
queryConfig[0] = {
type: 'Portfolio Item',
key : 'eKanbanState',
attribute: 'ADSK Kanban State'
};
rallyDataSource.findAll(queryConfig, showAttributeValues);
rally.forEach loops over each key in the first argument and will execute the function passed as the second argument each time.
It will work with either objects or arrays.
For an array:
var array = [1];
rally.forEach(array, function(value, i) {
//value = 1
//i = 0
});
For an object:
var obj = {
foo: 'bar'
};
rally.forEach(obj, function(value, key) {
//value = 'bar'
//key = 'foo'
});
I think that the code to dynamically build a config using the "results" collection created by your query above and passed to your sample showAttributeValues callback, is going to look a lot like the example of dynamically building a set of Table columns as shown in:
Rally App SDK: Is there a way to have variable columns for table?
I'm envisioning something like the following:
// Dynamically build column config array for cardboard config
var columnsArray = new Array();
for (var property in results) {
for (var i=0 ; i < results[property].length ; i++) {
columnsArray.push("'" + results[property][i] + "'");
}
}
var cardboardConfig = {
{
attribute: 'eKanbanState',
columns: columnsArray,
// .. rest of config here
}
// .. (re)-construct cardboard...
Sounds like you're building a neat board. You'll have to provide the board with the list of columns to show each time (destroying the old board and creating a new one).
Example config:
{
attribute: 'ScheduleState'
columns: [
'In-Progress',
'Completed'
]
}