enviroCar / enviroCar-server

Server of the enviroCar project
http://envirocar.org/
GNU Affero General Public License v3.0
31 stars 31 forks source link

Support Badges in User Profiles #114

Open autermann opened 11 years ago

autermann commented 11 years ago

Read Only! To add badges this snippet can be used:

db.users.update(
  { mail: "mail@example.de"},
  { $addToSet: { badges: "contributor" } }
);
dwilhelm89 commented 11 years ago

Are there already users with badges to test the feature?

autermann commented 11 years ago

I propose the following badge names:

These pledges were not taken, so we can ignore them:

I added the badge to Christophs profile to test it:

{
    "badges": [
        "contributor"
    ],
    "name": "staschc"
}
autermann commented 11 years ago

Add a later stage we also can use that field for something like achievements…

ubergesundheit commented 11 years ago

we could also add a badge for developers

nuest commented 11 years ago

+1 for the developer badge, this could be solved by allowing people to put their GitHub username in their profile in a specific field and then automatically bringing this together with https://github.com/enviroCar?tab=members.

nuest commented 11 years ago

Does the server provide an API for the existing badges? @matthesrieke ?

matthesrieke commented 11 years ago

not to my knowledge. @autermann ?

autermann commented 11 years ago

Badges are already supported, but, as we don't have any admin interface, the only way to add (and sie existing) badges is directly in the database. The API just shows them in the user profiles.

// add a single batch to a single user
db.users.update({
    _id: "username"
}, {
    $addToSet: {
        badges: "badge"
    }
});

// add several badges to a single user
db.users.update({
    _id: "username"
}, {
    $addToSet: {
        badges: {
            $each: [ "badge1", "badge2" ]
        }
    }
});

// add several badges to several users
db.users.update({
    _id: {
        $in: [ "username1", "username2" ]
    }
}, {
    $addToSet: {
        badges: {
            $each: [ "badge1", "badge2" ]
        }
    }
}, {
    multi: true
});

// get all existing badges
db.users.aggregate(
    { $project: { _id: false, badges: true} },
    { $unwind: "$badges" },
    { $group: { _id: 1, badges: { $addToSet: "$badges" } } }
).result[0].badges

The API:

curl -su ****:**** https://envirocar.org/api/dev/users/staschc \
    | python -m json.tool
{
    "badges": [
        "contributor"
    ],
    "name": "staschc"
}
nuest commented 11 years ago

Thanks for the clarifications, imho is a simple user interface important to manage the badges because that is a task that should not keep developers / admins busy: https://github.com/enviroCar/enviroCar-www/issues/115

matthesrieke commented 11 years ago

going for a dedicated REST resource / mongo collection.

REST resource planned as

{
"badges": [
  {
    "name":"contributor",
    "displayName": {
        "en": "Contributor",
        "de": "Unterstützer"
    },
    "description": {
        "en": "an enviroCar contributor",
        "de": "ein enviroCar unterstützer"
    }
  }
]
}

thoughts? @nuest

nuest commented 11 years ago

Is that for all available badges, or for the badges of one user?

For all available badges we should manage the Icon (full URL, or just the name?) server side as well.

matthesrieke commented 11 years ago

for all available badges: e.g. https://envirocar.org/api/dev/badges

We can store those via the webapp, but I would not provide the URL in the JSON. Icon could then be available at https://envirocar.org/api/badges/name.png

nuest commented 11 years ago

Right. Ok - will you let me know at https://github.com/enviroCar/enviroCar-www/issues/39 when this is done? Thanks!

autermann commented 11 years ago
nuest commented 11 years ago

@autermann Regarding your second point, if I understood @matthesrieke correctly that's what he wants to do, "for all available badges: e.g. https://envirocar.org/api/dev/badges"

And Accept-Language for getting the image instead of json, right? Sounds great to me.

matthesrieke commented 11 years ago

Accept-Language for reducing the JSON contents, e.g. only returning "de" for "description".

https://github.com/enviroCar/enviroCar-server/pull/142 already provides the /badges. users/:user/badges is also n2h, but as badges are currently encoded within the User resource, I would like to postpone this.

autermann commented 11 years ago

And Accept-Language for getting the image instead of json, right? Sounds great to me.

Not really :D Accept would be the way to go there... I would use the Accept-Language header to not have big map of translations in every object.

nuest commented 11 years ago

Ups :-). Ok, so I'm in favour of both Accept for the icon and Accept-Language to reduce the traffic footprint.

ahitch commented 11 years ago

Although I was using the english webpages, the badges came up in German. If we can only show in one laguage, it should be in english.

matthesrieke commented 11 years ago

I guess www is still using a mockup for that and not https://envirocar.org/api/stable/badges - thats probably the reason for the german names.

MartinDueren commented 11 years ago

No the mockup I'am using is in both languages. For me it works in the "show all badges" modal window. The badge below my avatar on the dashboard however remains in english since this does not come from the mockup, but I will fix it. @ahitch I can not reproduce the error you are describing.

ahitch commented 11 years ago

using FF badges deutsch

matthesrieke commented 11 years ago

I add some more badges to the DB. @MartinDueren you could use that resource now. @ahitch could you review the contents? these are just drafts. still the names (e.g. "localStakeholder") should be final.

https://envirocar.org/api/stable/badges

edit: here is the markup well-formatted in case you do not have a browser plugin:

{
   "badges":[
      {
         "name":"contributor",
         "displayName":{
            "de":"Erster Mitwirkender",
            "en":"First Contributor"
         },
         "description":{
            "de":"Einer der ersten enviroCar Mitwirkenden",
            "en":"A first enviroCar contributor"
         }
      },
      {
         "name":"supporter",
         "displayName":{
            "de":"Erster Unterstützer",
            "en":"First Supporter"
         },
         "description":{
            "de":"Einer der ersten enviroCar Unterstützer, der zu dem Erfolg der Indiegogo-Kampagne beigetragen hat",
            "en":"A first enviroCar supporter which helped to make the Indiegogo campaign a success"
         }
      },
      {
         "name":"localStakeholder",
         "displayName":{
            "de":"Erster lokaler Projektbeteiligter",
            "en":"First local stakeholder"
         },
         "description":{
            "de":"Einer der ersten lokalen enviroCar Projektbeteiligten, der die Indiegogo-Kampagne signifikant vorangetrieben hat",
            "en":"A first enviroCar local stakeholder which pushed the Indiegogo campaign significantly"
         }
      },
      {
         "name":"regionalStakeholder",
         "displayName":{
            "de":"Erster regionaler Projektbeteiligter",
            "en":"First regional stakeholder"
         },
         "description":{
            "de":"Einer der ersten regionaler enviroCar Projektbeteiligten, der die Indiegogo-Kampagne signifikant vorangetrieben hat",
            "en":"A first enviroCar local stakeholder which pushed the Indiegogo campaign significantly"
         }
      },
      {
         "name":"developer",
         "displayName":{
            "de":"enviroCar Entwickler",
            "en":"enviroCar developer"
         },
         "description":{
            "de":"einer der Entwickler!",
            "en":"one of the devs!",
            "1337":"I. Need. Coffee!"
         }
      }
   ]
}
ahitch commented 11 years ago

Just for clarity: the "description" appears in the mouse over box, correct? If so, the current mouse over blurbs say "One of the first enviroCar contributors" Which I prefer to what I read (no browser plug in I guess). Thus: "One of the first enviroCar contributors" "One of the first enviroCar supporters, who helped make the Indiegogo campaign a success" "One of the first enviroCar local stakeholders, who significantly supported the Indiegogo campaign" "One of the first enviroCar regional stakeholders, who significantly supported the Indiegogo campaign" "One of the enviroCar developers!" (auch gerne mit dem I need coffee)

I would capitalize Each word in the badge, e.g. "First Regional Stakeholder", "enviroCar Developer"

matthesrieke commented 11 years ago

thx. adjusted it accordingly.