Select interaction 'select' event - openlayers-3

I have created a select interaction for my ol3 map and attached a select event handler.
selectInteraction = new ol.interaction.Select({
...
});
selectInteraction.on('select', function (evt) {
???;
});
How do I interrogate 'evt' to determine:
Which feature was clicked to fire the event?
The ID and other attributes of this feature?
Whether the feature was selected or deselected?

The select event emitted by the ol.SelectInteraction is documented here.
As you can see, evt.selected will be an array of all features that were just selected. It will not contain already selected features which are kept selected when clicking a new feature while the addCondition is true. These are the clicked features that were not already selected and matched the filters to be included in the selection.
Likewise, evt.deselected will contain any features that were just deselected.
You can get the ID and properties of each feature with:
var featureID = feature.getId()
var properties = feature.getProperties()
var someSpecificProperty = feature.get("property-name")
See the docs for ol.Feature for more info on the feature and it's attributes.

Here are some items that should help you.. evt.selected gets you the features that are selected. This example is on a clustered layer and you can use the get function on features selected to retrieve properties from the object selected. If you don't know properties available to you then use console.dir(evt) to examine the object using the console.
selectInteraction.on('select', function(evt){
var coord = evt.mapBrowserEvent.coordinate;
var selItems = evt.selected;
var sellength = selItems.length;
var rptFrame = parent.window.frames["rptframe"];
for (var i = 0; i < sellength; i++) {
var label = selItems[i].get('l');
var url = selItems[i].get('url');
if (url) {
rptFrame.location.href = url;
} else {
var feaObj = selItems[i].get('features');
if (feaObj.length == 1) {
url = feaObj[0].get('url');
rptFrame.location.href = url;
} else {
writeMultiSelect(rptFrame,selItems);
}
}
}
});

Related

Listing WorkItem State Reasons programmatically

We have a customised TFS workflow, I want to be able to access the Reasons I can close a Bug (change the state from Active to Closed) from TFS so that we don't have to update our code every time we want to tweak our process.
This is what I have so far:
WorkItemType wiType = this.GetWorkItemStore().Projects[this.ProjectName].WorkItemTypes["Bug"];
var reason = wiType.FieldDefinitions["Reason"];
var state = wiType.FieldDefinitions["State"];
var filterList = new FieldFilterList();
FieldFilter filter = new FieldFilter(wiType.FieldDefinitions[CoreField.State], "Active");
filterList.Add(filter);
var allowedReasons = reason.FilteredAllowedValues(filterList);
However I'm not getting any results. I'd like to get a list of all the reasons why I can close a bug (Not Reproduceable, Fixed etc)
There isn't any easy way to get the transition via API directly as I know since the API read the allowed values from database directly.
The alternative way would be export the workitemtype definition via WorkItemType.Export() method and then get the information from it. Vaccano's answer in this question provided the entire code sample you can use.
Edited to give an example of how I solved this using the above recommendation:
public static List<Transition> GetTransistions(this WorkItemType workItemType)
{
List<Transition> currentTransistions;
// See if this WorkItemType has already had it's transistions figured out.
_allTransistions.TryGetValue(workItemType, out currentTransistions);
if (currentTransistions != null)
return currentTransistions;
// Get this worktype type as xml
XmlDocument workItemTypeXml = workItemType.Export(false);
// Create a dictionary to allow us to look up the "to" state using a "from" state.
var newTransistions = new List<Transition>();
// get the transistions node.
XmlNodeList transitionsList = workItemTypeXml.GetElementsByTagName("TRANSITIONS");
// As there is only one transistions item we can just get the first
XmlNode transitions = transitionsList[0];
// Iterate all the transitions
foreach (XmlNode transition in transitions)
{
XmlElement defaultReasonNode = transition["REASONS"]["DEFAULTREASON"];
var defaultReason = defaultReasonNode.Attributes["value"].Value;
var otherReasons = new List<string>();
XmlNodeList otherReasonsNodes = transition["REASONS"].SelectNodes("REASON");
foreach (XmlNode reasonNode in otherReasonsNodes)
{
var reason = reasonNode.Attributes["value"].Value;
otherReasons.Add(reason);
}
// save off the transistion
newTransistions.Add(new Transition
{
From = transition.Attributes["from"].Value,
To = transition.Attributes["to"].Value,
DefaultReason = defaultReason,
OtherReasons = otherReasons
});
}
// Save off this transition so we don't do it again if it is needed.
_allTransistions.Add(workItemType, newTransistions);
return newTransistions;
}

Breeze js cherry pick saves issue

I have a bulk insert screen which allows the user to insert products line by line.. Each product has it's own Units of measurement.
Here is my save changes Code:
save = function (product) {
var entitiesToSave = product.units().slice();
entitiesToSave.push(product);
var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
return manager.saveChanges([entitiesToSave],so)
.then(saveSucceeded)
.fail(saveFailed);
}
Once I try to save; I get this message:
The 'entities' parameter is optional or it must be an array where each element must be an entity
Modifying the code to:
save = function (product) {
var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
return manager.saveChanges([product,product.units()[0]],so)
.then(saveSucceeded)
.fail(saveFailed);
}
Works fine for one product unit.. However, I needed to save a specific product with all of it's units
in one shot..
Any help is appreciated.
For those who might have similar issue; I got it fixed by modifying the code to the following:
save = function (product) {
var entitiesToSave = new Array(product);
product.Units().forEach(function (Unit) {
entitiesToSave.push(Unit);
});
var so = new breeze.SaveOptions({ allowConcurrentSaves: true })
return manager.saveChanges(entitiesToSave,so)
.then(saveSucceeded)
.fail(saveFailed);
}
Regards to all.

how to create dynamic url in collection and model using backbone

My collection and model like this:
detail_userid = 0;
detail_contactid = 0;
var ContactDetail = Backbone.Model.extend({
urlRoot: URL_CONTACTS1+detail_userid+"/"+detail_contactid
});
var ContactDetailCollection = Backbone.Collection.extend({
model: ContactDetail,
url: URL_CONTACTS1+detail_userid+"/"+detail_contactid
})
The entrance is:
ContactDetailManagePageModel.prototype.init = function(m,n){
detail_userid = m;
detail_contactid = n;
var myContactDetails = new ContactDetailCollection();
var contactDetailListView = new ContactDetailListView({
collection: myContactDetails
});
myContactDetails.fetch({reset:true});
}
But when it runs,the url is :http://localhost:8080/ws/users/contacts/0/0,it means that the assignment to detail_userid and detail_contactid is unsuccessful,I don't know why.
Hope for your help.Thanks.
I think you are statically definining the urlRoot and url properties before you are running the init of the PageModel (not quite sure where you are getting m and n from though...)
Both url and urlRoot can be a function, so you can pass in options during instantiation and have them dynamically set on the model.
Simple example covering defining the collection and then creating one
var ContactDetailCollection = Backbone.Collection.extend({
model: ContactDetail,
url: function(){
return URL_CONTACTS1 + this.options.detail_userid + "/" + this.options.detail_contactid;
}
});
var myContactDetails = new ContactDetailCollection({
detail_userid: foo,
detail_contactid: bar
});
As I mentioned, I'm not sure what your init function is doing, I'm guessing it's something custom from your app that I don't need to worry about.
I'm fairly sure the main thing to take away is to set url and urlRoot dynamically
I would fulfill the accepted answer with few remarks.
First parameter when initializing Backbone.Collection is array of models, then options. To create an empty collection with options you should do next
var c = new Backbone.Collection(null, {opt1: val1, opt2: val2});
Actually, you can't access this.options in url function, bec. there are no options like in a model. What you can do, is assign required properties from options upon initialization.
initialize: function (models, options) {
// `parseInt()` is used for consistency that `id` is numeric, just to be sure
this.detail_userid = parseInt(options.detail_userid);
this.detail_contactid = parseInt(options.detail_contactid);
}
Later you can access them like this:
url: function() {
return URL_CONTACTS1 + this.detail_userid + "/" + this.detail_contactid;
}
I wanted to use the HATEOAS href from one model to fetch data of another model. It worked to simply set the url on the newly created collection instead of defining it right away in the constructor.
var DailyMeasuresCollection = Backbone.Collection.extend({
//url : set dynamically with collection.url = url
model : DailyMeasuresModel,
parse : function(data) {
return data._embedded.dailyMeasures;
}
});
var DailyMeasuresTopicListItemView = Backbone.View.extend({
//...
events : {
'click .select-topic' : 'onClick'
},
onClick : function() {
var topicMeasures = new DailyMeasuresCollection()
topicMeasures.url = this.model.attributes._links.measures.href // <- here assign
var topicMeasuresView = new DailyMeasuresListView({
collection : topicMeasures
});
topicMeasures.fetch()
}
});

Google Script Get UI textbox value

I have created a simple GUI with 2 textboxes and 1 button. The button handler goes as below
function handleButton1(e)
{
var app = UiApp.getActiveApplication();
var v1 = e.parameter.TextBox1;
var v2 = e.parameter.TextBox2;
Logger.log(v1);
app.getElementById("TextBox1").setText(v2);
app.getElementById("TextBox2").setText(v1);
return app;
}
When I run the app the textbox values are TextBox1 and TextBox2.
When press button then both the textbox value displayed is undefined.
Where am I going wrong.
With a server-side click handler, you need to explicitly include values in the handler event by using .addCallbackElement(). If you do so, the current value of the named elements you add will be included in the event delivered to your handler.
Since you are seeing undefined, it's likely that you didn't add the callbacks. You should have something like this in your UI definition:
var handler = app.createServerHandler('handleButton1')
.addCallbackElement(textBox1)
.addCallbackElement(textBox2);
button.addClickHandler(handler);
The name of the element will be used to label the callback value (.setName()), while the id will be used to access the element in your handler (.setId()).
Here's a working version of your script:
function doGet() {
var app = UiApp.createApplication();
var textBox1 = app.createTextBox().setName("TextBox1").setId("TextBox1");
var textBox2 = app.createTextBox().setName("TextBox2").setId("TextBox2");
var button = app.createButton('Swap Contents');
app.add(textBox1).add(textBox2).add(button);
var handler = app.createServerHandler('handleButton1')
.addCallbackElement(textBox1)
.addCallbackElement(textBox2);
button.addClickHandler(handler);
return app;
}
function handleButton1(e)
{
//Logger.log(JSON.stringify(e));
var app = UiApp.getActiveApplication();
var v1 = e.parameter.TextBox1;
var v2 = e.parameter.TextBox2;
app.getElementById("TextBox1").setText(v2);
app.getElementById("TextBox2").setText(v1);
return app;
}

umbraco - usercontrols - umbracoNaviHide

I know I can get the current node with 'var top = Node.GetCurrent();' but I cant seem to find where I can get the related properties, specifically 'umbracoNaviHide'. I'd like to know how to access the same data that is accessible from XSLT in a user control
To get properties you need to use the GetProperty() method.
var top = Node.GetCurrent();
top.GetProperty("umbracoNaviHide").Value;
In Umbraco 8, you will have to do something like this:
private List<NavigationListItem> GetChildNavigationList(IPublishedContent page)
{
List<NavigationListItem> listItems = null;
var childPages = page.Children.Where(i => i.IsPublished());
if (childPages != null && childPages.Any() && childPages.Count() > 0)
{
listItems = new List<NavigationListItem>();
foreach (var childPage in childPages)
{
int myTrueFalseFieldValue = 1;
if (childPage.HasProperty("umbracoNaviHide"))
{
Int32.TryParse(childPage.GetProperty("umbracoNaviHide").GetValue().ToString(), out myTrueFalseFieldValue);
//myTrueFalseFieldValue = 0 // hide the page
//myTrueFalseFieldValue = 1 // don't hide the page
string name = childPage.Name;
int test = myTrueFalseFieldValue;
}
if (myTrueFalseFieldValue == 1)
{
NavigationListItem listItem = new NavigationListItem(new NavigationLink(childPage.Url, childPage.Name));
listItem.Items = GetChildNavigationList(childPage);
listItems.Add(listItem);
}
}
}
return listItems;
}
Above code will make sure that those pages which have set there umbrachoNaviHide checkbox property to true will not be included in the navigation list.
In order to see how to make custom property: umbracoNaviHide, please search youtube for "Day11: Hide Pages from Navigation in Umbraco"

Resources