I'm creating an application in the MERN stack and I stumbled upon a problem. I will start by explaining how that app is going to work.
So, in that application users can create their Collections. It can be anything - a collection of books, a collection of a favorite food - anything. Now in these Collections, they can create Items - for example, specific books.
We can navigate through the application to the different Collection Pages or the specific Item Pages in those Collections. You get the idea. There is a list of all the Collections on the main page and we can click e.g. Books Collection, then click on the Harry Potter item, and we will visit the Page for that specific book.
When a user creates an Item, he has to add a name and tag to it. But the user can set his own fields, like for example Author field for that Books Collection. Then every Item (book) will gain that Author field. It's obvious, that the main Item Schema is not affected by that additional field. Because we don't wanna the Author field in the Favourite Food Collection.
Anyway, I know how to modify data of already existing Items, but how to change that Schema for an Items that user gonna create in the future? Because if the user added Author field, we obviously want that field to show every time that user creates a new Item (book) in that certain Collection. Should I create a whole new Schema, only for the modified document? Or is there a different, more approachable way of achieving what I want right here?
As far as saving dynamic data in the collection, you could use Mixed Type or Object Type, see more info here
For keeping track of the fields the user has used previously, we could maintain a array within, having all the fields
Related
I have a view of entities which are being displayed based on an entity type filter. I now need to reorder these and would like to use the built in 2sxc functionality to do this, so I have a created a new view of the data using the "module data source" so that the ordering will work.
But how do I now make all of the existing entities of the same type (definition) appear in this new view? The view now displays one item by default and I can replace that one item. But how do I add multiple existing items? I need the Entity ID's to remain the same for Query String usage and SEO.
Thanks, hope the question makes sense.
Cheers
I believe that you are asking "how can I add many items to an instance (module) manually, so that I can also sort them manually" - is this correct?
If yes, then you must make sure your template supports lists (checkbox in the template settings). This then gives you a [+] button; but you don't want to use that, as it would be for typing in new data. There's another button called "add an empty demo entry" which you'll see as a round (+) after pressing the more ... button once. Pressing this will give you empty entries, into which you can then replace existing items.
I am building a three-way selector: companies, departments and users.
I am trying to figure out the best way to structure this in my Backbone app. Here's the current problem I'm having.
Say a user has selected a company. Then, the departments and user collections will be populated and the view will update:
The user can then select a department from the list, which will further refine the user select. This I have working well.
Or, the user can go straight to User list and find a user (without first having to specify a department). In this case, the view for both departments and users needs to update:
The department should become selected on the user's department.
The users should refine to all users in the selected user's department, rather than all user's in the selected company.
I am struggling with the best way to do this. So far, my departments and users collections have a selected property, so that's how I'm maintaining state. Currently I'm doing something like
When the user selects a department, the department view
Sets the selected department directly on the departments collection
Triggers an event
The users collection hears the event, clears out any selected user, and triggers another event
The users view hears the event, and re-renders. Since it knows about the departments collection, it knows a department has been selected and that it should refine the users down to the department
I do this because if I had the view only trigger the event (without setting the departments selected property first), I would have a race condition: both the departments and users collections would be responding to the event, and depending on the timing the users may not be properly refined.
The second piece:
When the user selects a User (without specifying a department), the user view
Sets the selected user directly on the users collection
Sets the selected department directly on the departments collection (which it knows about)
Triggers an event
and this is where I'm stuck. The departments collection doesn't really need to do anything, since its selected property is already correct; really, its view just needs to re-render. And so does the users' view.
But this is not all, because there are lots of other things that can happen. I feel like it's getting out of control.
What's the best to structure this?
Am I using events properly?
How do you deal with a view that needs to hear about other views and other collections changing?
Update: Should I just use routes to save application state? This may simplify things...
Update 2: This question has been helpful to me. Having a separate model to manage state definitely seems the way to go.
Update 3: Having a separate model to store state + the use of jQuery deferreds is amazing. Seriously. It completes me.
I find it useful to use a model for keeping track of the state. That way you can pass that model around to different views and don't have views referencing each other directly.
You can use built-in and custom events on the state model to manage state transitions.
In your case collections would not need to store selected. Instead selectedUser and selectedDepartment could be attributes of the state model.
Then you could have logic in your model that triggers custom events ('update:users:view' or 'update:departments:view') depending on what is selected.
I hope that makes sense.
I have a custom object with a lookup field (foreign key) to the User table. I added a "custom object" tab to my app to list these items.
What I think I want is the functionality provided by a "master detail" relation. Sadly, this is not available when referencing the user model from a custom object.
When a given logged-in user views this tab, I want them to see any items if they have access to the User referenced in this lookup field. I suspect that this list view is going to show all items that BELONG to the logged in user (i.e created by). It's difficult to test because of the limited user licenses available in the dev edition.
For a logged in user, what is the best way to display the correct items regardless of who created them?
Instead of creating a new lookup field to the user object, why not just use the record owner?
The record owner doesn't have to be the person that created the record, and you can then create a View for 'My Object__c' that will only show items owned by the logged in user.
If this is no help, can you please elaborate on your requirements?
My question deals with this UI sample.
Having trouble with approach to managing the "selected" state of various UI view components. For example, I have menus above from which the user makes various selections. These selections should cause updates in the menus themselves (HL selected items) and also cause updates in the results, which would be based on the selections made. Also, the menus have different kinds of rules. For example, you can only have one "list" selected at a time, but you can have multiple "tags" selected.
One approach that I was thinking about was to create a Backbone model that holds the state of the UI "selection". For example, I could have a model SearchCriteria that holds this information. Then, when a user makes choices in the UI, I could update this model. I could have the various view components listen for changes in this model (as well as changes in the primary data models.) Then, the views would update their visual state by updating which items are shown as selected.
One item I am struggling with in this approach is who should be responsible for updating the selected state of an item. For example, on the list of tags, I might have the following pieces defined...
Tag (model to represent a tag)
TagCollection (collection to represent a collection of tags)
TagMenuView (view that represents the menu of tags available to select)
TagMenuItemView (view that represents a single item in the menu)
Should I...
Set up an event listener on the TagMenuItemView for click, and then try to handle 1) updating the SearchCriteria model, and 2) updating the visual state of the menu, e.g. selected items?
Or, should I have the higher level view (the TagMenuView) listen for events such as the user selecting a tag, and perform the work there?
Also, the tags menu in this example allows multiple items to be selected, but the lists menu would only allow one list at a time to be selected. Where would this "UI" rule (or is this really a business rule related to a search?) be enforced? For example, if I listened for click events on each individual list menu item, I could certainly update the visual state of that item, but, I also need to make sure the higher level menu view deselects any other selected lists. So, would it be better to manage the "UI" state of something like the to-do list menu in the view that would represent that entire menu (a ToDoListMenuView) rather than on each individual menu item view?
Sorry for so many questions. I am just having a hard time moving to this model of development.
You're almost to an answer similar to the one I would use.
If you appreciate that list, search, due and tags are search filters on a big collection of to-dos, you are 90% of the way to enlightenment. In fact, other than search, all of those are just "kinds of tags"! (Unless you have 10,000 to-do items, there are no performance or memory-related reasons to have lists of lists of to-dos; "Work", "Project #1", and "Personal" are just specialized tags by which you filter items out of your view, showing only those related to one sphere of your life or another.)
Create the SearchCriteria model. (You are not technically searching, you're filtering: you're excluding from your view those things that don't match your search criteria.) This model will hold a lot of attributes about your client state. Your search criteria are almost entirely driven by data present in the client (since the search applies to only one ToDoList at a time), so it's entirely SearchCriteria related, not ToDo object related.
All Views bind to change/add/remove events on SearchCriteria. When the user clicks on any of the views (list, view, tag), that message is forwarded to SearchCriteria. It makes the appropriate internal changes, which in turn triggers the views to re-render themselves. One of the event recipients in the main ToDoListView, which during its render then checks the search criteria. Something like:
ToDoListView = Backbone.View.extend({
...
render: function() {
var self = this,
toDraw = this.collection.filter(
function(c) { return this.searchCriteria.passes(c); });
$(this.el).html('');
_.each(toDraw, function(c) {
(new ToDoItemView({model: c, parent: self})).render(); });
}
That may be a little personally idiomatic, passing in the parent object and letting the item insert itself into the parent's DOM object. You could pass in anything: the element to be appended to. Alternatively, render could return a DOM object and the ListView could do the appending. That's a matter of taste. I've done both.
You do have to dig a little into backbone's parent library, underscore, to grok the essential wonderfulness of the _.each() usage.
Also, I've often contained an entire Backbone application in a self-executing anonymous function, and leaving "searchCriteria" as a variable accessible to all objects within the scope of the SEAF, so it wouldn't be this.searchCriteria, but just searchCriteria.
You can also write SearchCriteria so it calls sync, writing event state to the server, which you can then save as a raw JSON object; the nice thing about sync is that if what you send and what you receive are the same, no events are triggered, so you don't get a double-render effect, and the nice thing about using JSON is that it's client-appropriate, but contains nothing that the server's ToDo relationships care about.
Furthermore, you can specify specific client-side behavior rules. Such as: when you change ToDo Lists, you can apply the text-search criteria, or, as an alternative, you can decide that changing lists clears the text-search criteria field; doing so will trigger an event that will cause the "TextSearchView" to clear its input box (you'll have to write that event handler, but it'll be obvious you meant to do that). You can make up any rule you like, such as "changing lists clears all selections," but that doesn't seem sensible. I can easily imagine trying to tackle the bugs in my "project" list and in my personal life. But clearing the search box just seemed more... sensible, if you know what I mean.
Hi I am trying to create a Custom Object in Salesforce.com Developer Edition, because I would then like to use this Custom Object in a New Custom Tab say "Properties". Properties tab will contain information about Realestate Properties, like # of rooms, bath rooms etc.
The problem I cannot seem to get around is how do I create a Custom Object that has many attributes. When I go to Setup->Create->Objects it only has one Label in the Custom Object definition page. I am expecting many attributes/labels I can add so I can then put this into the new Tab.
I've been looking at this for a while and I do not see a solution, so I am assuming I am looking at this wrong. Could someone recommend a solution or a book, article that would show me what I am missing.
Thanks
The custom objects page shows a list of all the custom objects you have created. If you click on the label, it takes you to the object definition. To add more attributes (called "fields" in Salesforce), go to the "Custom Fields & Relationships" section on the object detail page. Click to "New" button to add new fields from there.
Salesforce has a huge amount of publicly available training material available online.
The fundamentals doc should provide you with what you need immediately (http://www.salesforce.com/us/developer/docs/fundamentals/index.htm).
I also recommend looking at the training courses available on iTunes (search for Salesforce).