Hi Guys,

I'm trying to find the best way to implement the following functionality
with AngularFire 0.8 and would appreciate some guidance if possible (see
concrete questions at the end)

My data structure looks like this: (complexity reduced to show only what is
relevant)

user.portfolios.portViews = [
     { viewName: 'view1',
       columnsInView: [
         { colName: 'column1' },
         { colName: 'column2' },
         ...
         ...
       ],
       settings: { selected: true }
     },

     { viewName: 'view2',
       columnsInView: [
         { colName: 'column2' },
         { colName: 'column4' },
         ...
         ...
       ],
       settings: { selected: true }
     },

     { viewName: 'view3',
       columnsInView: [
         { colName: 'column1' },
         { colName: 'column6' },
         ...
         ...
       ],
       settings: { selected: false }
     }

Functionality: the app should show in a table the columns of the selected
views only, without repeating columns, which could happen. So, after I read
the data, I have an internal function using angular.forEach to generate a
show-table and then I put it in the $scope to render the view. The user can
select/deselect views and then the 'selected' value in 'settings' object
should change accordingly and a new show-table is generated and updated in
the view. I'm also using localStorage to persist info between sessions. So
I need to keep also localStorage synced. The user is the only one allowed
to modify the data.

My approach for the moment is:
I'm synching the whole 'portViews' array with $asArray() method and always
copying the data manually to localStorage, either at the beginning of each
session or after the user changes data. I'm also extending the factory
using $FirebaseArray.$extendFactory to add a method to synced 'portViews'
array where I have the code to generate the show-table. But I'm triggering
this manually when user changes 'settings' object or when I set the data at
the beginning of sessions.
After the user changes locally the view I'm updating the 'settings' object
in the firebase server using a $set on a $firebase wrapper of the relevant
Ref. And at the same time updating again localStorage and local memory.

Questions:

In general my feeling is that I'm overdoing a bit things here syncing with
$asArray() since the user is the only one allowed to modify this info. I
have also the feeling that extending the factory is a bit too much but I
wanted that approach because in the future I might need more functionality
linked to the synced array. What would be your take on this?

I would prefer to avoid using the $set to update the settings object and
use directly $save on the synced array but since the data to modify is a
couple of levels deeper I was getting an error of not allowed parameters
(beginning with $$). I believe for this I would need to use the toJSON
method to correctly parse the data but I was struggling implementing
that... what would be the best approach for this?

Some other tips in general for this?

Please let me know if you'd need more info which I'll happily provide.
Thanks in advance,
Alex

--
You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
To post to this group, send email to firebase-angular@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/6cd4e8eb-0d2d-4ea4-b121-6c6f0df2d759%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Michael Wulf at Aug 11, 2014 at 6:27 pm
    Alex,

    Could you create a fiddle/gist/plnkr/jsbin that showcases what you're
    trying to do? It's not really clear what this data structure is intended to
    accomplish or how you're utilizing $asArray(). I don't see any data that is
    a "couple of levels deeper" so I'm struggling to understand this part of
    the use case as well.

    Speaking in generalizations, you'll usually want to flatten data
    <https://www.firebase.com/docs/web/guide/structuring-data.html>, avoid
    arrays
    <https://www.firebase.com/docs/web/guide/understanding-data.html#section-arrays-in-firebase>,
    and rely heavily on the best practices listed in those docs. Applying those
    principles, this data *could be* structured something like this, assuming
    it was an appropriate model for your use case:

    /user/$user_id/...

    /portfolios/$user_id/$portfolio_id/viewName
    /portfolios/$user_id/$portfolio_id/settings/...

    (columns are a set, no dups, no need for an array, just store them by key
    and refer to them by their unique name)
    /portfolios/$user_id/$portfolio_id/columns/$column_name/true

    (some big data that you don't want to iterate every time you fetch a list
    of portfolios)
    /portfolio_data/$user_id/$portfolio_id/...

    Now to use this with AngularFire, I could do something like this
    <https://gist.github.com/katowulf/631c8189ec9c240448e2>.

    Cheers,
    Kato

    On Mon, Aug 11, 2014 at 7:31 AM, Alex Tomas wrote:

    Hi Guys,

    I'm trying to find the best way to implement the following functionality
    with AngularFire 0.8 and would appreciate some guidance if possible (see
    concrete questions at the end)

    My data structure looks like this: (complexity reduced to show only what
    is relevant)

    user.portfolios.portViews = [
    { viewName: 'view1',
    columnsInView: [
    { colName: 'column1' },
    { colName: 'column2' },
    ...
    ...
    ],
    settings: { selected: true }
    },

    { viewName: 'view2',
    columnsInView: [
    { colName: 'column2' },
    { colName: 'column4' },
    ...
    ...
    ],
    settings: { selected: true }
    },

    { viewName: 'view3',
    columnsInView: [
    { colName: 'column1' },
    { colName: 'column6' },
    ...
    ...
    ],
    settings: { selected: false }
    }

    Functionality: the app should show in a table the columns of the selected
    views only, without repeating columns, which could happen. So, after I read
    the data, I have an internal function using angular.forEach to generate a
    show-table and then I put it in the $scope to render the view. The user can
    select/deselect views and then the 'selected' value in 'settings' object
    should change accordingly and a new show-table is generated and updated in
    the view. I'm also using localStorage to persist info between sessions. So
    I need to keep also localStorage synced. The user is the only one allowed
    to modify the data.

    My approach for the moment is:
    I'm synching the whole 'portViews' array with $asArray() method and always
    copying the data manually to localStorage, either at the beginning of each
    session or after the user changes data. I'm also extending the factory
    using $FirebaseArray.$extendFactory to add a method to synced 'portViews'
    array where I have the code to generate the show-table. But I'm triggering
    this manually when user changes 'settings' object or when I set the data at
    the beginning of sessions.
    After the user changes locally the view I'm updating the 'settings' object
    in the firebase server using a $set on a $firebase wrapper of the relevant
    Ref. And at the same time updating again localStorage and local memory.

    Questions:

    In general my feeling is that I'm overdoing a bit things here syncing with
    $asArray() since the user is the only one allowed to modify this info. I
    have also the feeling that extending the factory is a bit too much but I
    wanted that approach because in the future I might need more functionality
    linked to the synced array. What would be your take on this?

    I would prefer to avoid using the $set to update the settings object and
    use directly $save on the synced array but since the data to modify is a
    couple of levels deeper I was getting an error of not allowed parameters
    (beginning with $$). I believe for this I would need to use the toJSON
    method to correctly parse the data but I was struggling implementing
    that... what would be the best approach for this?

    Some other tips in general for this?

    Please let me know if you'd need more info which I'll happily provide.
    Thanks in advance,
    Alex

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6cd4e8eb-0d2d-4ea4-b121-6c6f0df2d759%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6cd4e8eb-0d2d-4ea4-b121-6c6f0df2d759%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/CAFHX4%3Dp7nyuZf%3DysnnbJO_UKKwV5HQjHBYWVgtcrsC-tYOCfcw%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alex Tomas at Aug 11, 2014 at 8:26 pm
    Kato,

    Thank you very much for your promptly answer. And also thanks for making
    your best to decipher what I wanted without me giving much clarity.
    The main problem is that I was really reluctant to change the structure of
    my data. I'm aware of the best practices in that regard but for different
    reasons didn't really wanted to do the work to adapt it. But it is becoming
    more and more clear that I need to do it. Especially to use much better the
    potential of Firebase and simplify things. I think for the moment I'll be
    updating that in my app and for sure will come back with other questions
    for that scenario in the future. For the moment, the structuring tips
    you're giving me will guide me well.

    Thanks
    Alex


    On Monday, August 11, 2014 8:27:07 PM UTC+2, Michael Kato Wulf wrote:

    Alex,

    Could you create a fiddle/gist/plnkr/jsbin that showcases what you're
    trying to do? It's not really clear what this data structure is intended to
    accomplish or how you're utilizing $asArray(). I don't see any data that is
    a "couple of levels deeper" so I'm struggling to understand this part of
    the use case as well.

    Speaking in generalizations, you'll usually want to flatten data
    <https://www.firebase.com/docs/web/guide/structuring-data.html>, avoid
    arrays
    <https://www.google.com/url?q=https%3A%2F%2Fwww.firebase.com%2Fdocs%2Fweb%2Fguide%2Funderstanding-data.html%23section-arrays-in-firebase&sa=D&sntz=1&usg=AFQjCNHpo0mrqvUR4ZENHX1e66K1xK_eBw>,
    and rely heavily on the best practices listed in those docs. Applying those
    principles, this data *could be* structured something like this, assuming
    it was an appropriate model for your use case:

    /user/$user_id/...

    /portfolios/$user_id/$portfolio_id/viewName
    /portfolios/$user_id/$portfolio_id/settings/...

    (columns are a set, no dups, no need for an array, just store them by key
    and refer to them by their unique name)
    /portfolios/$user_id/$portfolio_id/columns/$column_name/true

    (some big data that you don't want to iterate every time you fetch a list
    of portfolios)
    /portfolio_data/$user_id/$portfolio_id/...

    Now to use this with AngularFire, I could do something like this
    <https://gist.github.com/katowulf/631c8189ec9c240448e2>.

    Cheers,
    Kato


    On Mon, Aug 11, 2014 at 7:31 AM, Alex Tomas <alexb...@gmail.com
    <javascript:>> wrote:
    Hi Guys,

    I'm trying to find the best way to implement the following functionality
    with AngularFire 0.8 and would appreciate some guidance if possible (see
    concrete questions at the end)

    My data structure looks like this: (complexity reduced to show only what
    is relevant)

    user.portfolios.portViews = [
    { viewName: 'view1',
    columnsInView: [
    { colName: 'column1' },
    { colName: 'column2' },
    ...
    ...
    ],
    settings: { selected: true }
    },

    { viewName: 'view2',
    columnsInView: [
    { colName: 'column2' },
    { colName: 'column4' },
    ...
    ...
    ],
    settings: { selected: true }
    },

    { viewName: 'view3',
    columnsInView: [
    { colName: 'column1' },
    { colName: 'column6' },
    ...
    ...
    ],
    settings: { selected: false }
    }

    Functionality: the app should show in a table the columns of the selected
    views only, without repeating columns, which could happen. So, after I read
    the data, I have an internal function using angular.forEach to generate a
    show-table and then I put it in the $scope to render the view. The user can
    select/deselect views and then the 'selected' value in 'settings' object
    should change accordingly and a new show-table is generated and updated in
    the view. I'm also using localStorage to persist info between sessions. So
    I need to keep also localStorage synced. The user is the only one allowed
    to modify the data.

    My approach for the moment is:
    I'm synching the whole 'portViews' array with $asArray() method and
    always copying the data manually to localStorage, either at the beginning
    of each session or after the user changes data. I'm also extending the
    factory using $FirebaseArray.$extendFactory to add a method to synced
    'portViews' array where I have the code to generate the show-table. But I'm
    triggering this manually when user changes 'settings' object or when I set
    the data at the beginning of sessions.
    After the user changes locally the view I'm updating the
    'settings' object in the firebase server using a $set on a $firebase
    wrapper of the relevant Ref. And at the same time updating again
    localStorage and local memory.

    Questions:

    In general my feeling is that I'm overdoing a bit things here syncing
    with $asArray() since the user is the only one allowed to modify this info.
    I have also the feeling that extending the factory is a bit too much but I
    wanted that approach because in the future I might need more functionality
    linked to the synced array. What would be your take on this?

    I would prefer to avoid using the $set to update the settings object and
    use directly $save on the synced array but since the data to modify is a
    couple of levels deeper I was getting an error of not allowed parameters
    (beginning with $$). I believe for this I would need to use the toJSON
    method to correctly parse the data but I was struggling implementing
    that... what would be the best approach for this?

    Some other tips in general for this?

    Please let me know if you'd need more info which I'll happily provide.
    Thanks in advance,
    Alex

    --
    You received this message because you are subscribed to the Google Groups
    "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to firebase-angul...@googlegroups.com <javascript:>.
    To post to this group, send email to firebase...@googlegroups.com
    <javascript:>.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/firebase-angular/6cd4e8eb-0d2d-4ea4-b121-6c6f0df2d759%40googlegroups.com
    <https://groups.google.com/d/msgid/firebase-angular/6cd4e8eb-0d2d-4ea4-b121-6c6f0df2d759%40googlegroups.com?utm_medium=email&utm_source=footer>
    .
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Firebase + AngularJS" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to firebase-angular+unsubscribe@googlegroups.com.
    To post to this group, send email to firebase-angular@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-angular/3fd77739-37c1-415f-a9e1-4c9d0e823c74%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupfirebase-angular @
postedAug 11, '14 at 3:35p
activeAug 11, '14 at 8:26p
posts3
users2

2 users in discussion

Alex Tomas: 2 posts Michael Wulf: 1 post

People

Translate

site design / logo © 2021 Grokbase