How to fetch all the Todo lists and its corresponding Todos for a project from New Basecamp (bcx) API - ios

REFERRED https://github.com/basecamp/bcx-api/blob/master/sections/todos.md and https://github.com/basecamp/bcx-api/blob/master/sections/todolists.md
TRIED hitting the /todolists.json Basecamp bcx API (since I needed to show the todo lists as header/sections of the tableview displaying Project Todos).
GOT Names of the todo lists, their Descriptions (if any), and their respective URLs (amidst other not-so-useful-to-me info.)
Now, I have already used this URL (above) and hit it to fetch the list of todos (both completed and remaining) for that particular todo-list and got what I intended to; storing and displaying them, dynamically.
However, to me, this approach seems a bit amateurish as I am,a) storing the todo list in a mutable-array..b) hitting the API for each object of this mutable-array (above) and fetching an array of todos for a particular todo-list..c) storing this list (of todos) in a mutable-dictionary - key for which is the name of the todo-list..and finally,d) using this mutable-dictionary in the tableView:heightForRowAtIndexPath: and tableView:cellForRowAtIndexPath: methods for dynamically setting the tableView height and objects, respectively..
INTEND TO Get all the todo lists for a project WITH its corresponding todos as a response of a single Basecamp bcx API, for:
a) Improving the code quality,b) Decreasing the iteration time,c) Preventing headache of a person, if any, who is going to parse my code later in future

This currently isn't possible with the BCX API. If you want to see all of the todos on an individual project's todolists, you'll need to get each todolist separately.

I think this is probably available in the new API update. Kindly check.

Related

Angular 11 Material DataSource without further Requests to the Server

I've been playing around with the example table-schematic for the Material Design [version: 11.0.3] table.
Basically i want to make a request, take the response and display it with the options to sort and limit the displayed items (pagination).
It works fine if I just replace the content of the connect function with "return a mapped Observable of the Response" but then the sorting and pagination obviously don't work anymore (since they are deleted) and i can't figure out how to make them work.
I assume the example pagination and sorting requires the data to be already present when the page loads/initializes (e.g. with a static Array).
Putting the request in the connect() function, saving the objects of the response to a variable and subscribing does work. However the page does not update after filling the initially empty array with data until sorting or pagination settings change. Which would make sense to me.
My question is, how do i get the data in there once and use the same data for pagination and sorting.
Can I even use the schematic in this case or is it misleading?
You can initialize a MatTableDataSource using an array of data, and then it will handle paging, filtering, and sorting locally and not try to fetch any more data.
See this example: https://stackblitz.com/angular/nleleddqmel?file=src%2Fapp%2Ftable-overview-example.ts
This example creates the data array locally, but you would instead use the response from your server request.

Looping through list of objects created by createEntry() and editing their properties before doing submitChange()

Good afternoon fellow developers,
I have come across a scenario where I found myself needing to retrieve the list of pending changes from my model and editing a specific property of those entries before sending them to my back-end.
These are new entities I created using the createEntry() method of the OData model v2. But, at the time of creation of said entities, I do not possess the value I need to add to them yet. This is the list of entities I retrieve by using the getPendingChanges() method on my model:
What I need to do is to loop through each of these newly created entities and set a specific property into them before actually sending them to my back-end with the submitChanges() method. Bare in mind that these are entry objects created by the createEntry() method and exist only in my front-end until I am able to submit them with success.
Any ideas that might point me in the right direction? I look forward to reading from you!
I was able to solve this issue in the following way:
var oPendingChanges = this.model.getPendingChanges();
var aPathsPendingChanges = $.map(oPendingChanges, function(value, index) { return [index];});
aPathsPendingChanges.forEach(sPath => oModel.setProperty("/" + sPath + "/PropertyX","valueFGO"));
The first two instructions retrieve the entire list of pendingChanges objects and then builds an array of paths to each individual entry. I then use that array of paths to loop through my list of pending changes and edit into the property I want in each iteration of the loop. Special thanks to the folks at answers.sap for the guidance!

Realm Swift: Question about Query-based public database

I’ve seen all around the documentation that Query-based sync is deprecated, so I’m wondering how should I got about my situation:
In my app (using Realm Cloud), I have a list of User objects with some information about each user, like their username. Upon user login (using Firebase), I need to check the whole User database to see if their username is unique. If I make this common realm using Full Sync, then all the users would synchronize and cache the whole database for each change right? How can I prevent that, if I only want the users to get a list of other users’ information at a certain point, without caching or re-synchronizing anything?
I know it's a possible duplicate of this question, but things have probably changed in four years.
The new MongoDB Realm gives you access to server level functions. This feature would allow you to query the list of existing users (for example) for a specific user name and return true if found or false if not (there are other options as well).
Check out the Functions documentation and there are some examples of how to call it from macOS/iOS in the Call a function section
I don't know the use case or what your objects look like but an example function to calculate a sum would like something like this. This sums the first two elements in the array and returns their result;
your_realm_app.functions.sum([1, 2]) { sum, error in
if let err = error {
print(err.localizedDescription)
return
}
if case let .double(x) = result {
print(x)
}
}

When I try to save data to Firebase it only updates the existing data, Swift, Firebase

The way I set up my database structure was like this:
It starts with Lists then there is a child that shows the users UID then inside that there is one item.
The one item inside the UID gets updated every time I attempt to save new data. Instead of adding another item the same one just keeps changing. I was wondering how I could instead of update the same one item every time add more items.
The way that I save my data is with this line of code.
let user = FIRAuth.auth()?.currentUser
let item: String = self.ItemTextField.text!
self.ref.child("Lists").child(user!.uid).setValue(["Items": item])
More idiomatic is to store the list of items with so-called push ids:
Lists
twEymn...
-Km....: "Yoghurt"
You'd do this with:
self.ref.child("Lists").child(user!.uid).childByAutoId().setValue(item)
The childByAutoId() generates a unique, sequential ID. It's similar to an array index, but this one works reliably in multi-user environments and when users can be offline. Read this blog post about these so-called push ids.
Alternatively you can use the name of the item as the key (if the item has to be unique in the list):
Lists
twEymn...
"Yoghurt": true
In that case the code becomes:
self.ref.child("Lists").child(user!.uid).child(item).setValue(true)
One thing you'll note is that both of these approaches only deal with the newly added item, instead of the list of items as a whole. This is a general pattern you'll see when using Firebase. By isolating your modifications, your app will be more scalable without users getting into each other's way.
The problem is that you are setting a key-value pair ("Items" : item) so that each time it is updating the value for the same key. What you could do instead is ("Items" : [your array of items here]), which will update a list of items for the same key each time.
You could also fetch the current list of items, append your new item locally, and then update.

How to properly use createOrUpdateInRealm?

I am using Realm to handle persisting data to disk in my app. I am storing an ArticleCollection object to Realm (this just contains an array of NewsArticle objects).
I am using createOrUpdateInDefaultRealmWithValue to either create a new ArticleCollection or update the existing one (achieved using a primary key on ArticleCollection).
This currently works well when the app fetches new articles it will overwrite the current collection of articles and replace with a new instance of ArticleCollection.
The issue is that whilst ArticleCollection is replaced (in Realm brwoser I can see the count of ArticleCollection is always 1 as expected), the number of NewsArticles always increases. It seems that sub objects of ArticleCollection (NewsArticle) never get replaced/deleted, only appended to.
How can I ensure that when I use createOrUpdateInRealm, it will delete all sub objects?
Make sure that are also using a primary key on your NewsArticle object. Otherwise those news articles won't be updated. That's why you are seeing an increasing number of news articles.

Resources