Last active
December 22, 2015 00:58
-
-
Save camertron/6392632 to your computer and use it in GitHub Desktop.
Dashboard tiles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class DashboardTile | |
| PARAMS = [ | |
| :image, :name, :description, :count, | |
| :count_suffix, :status, :url, :url_class | |
| ] | |
| PARAMS.each do |param| | |
| define_method(param) { raise NotImplementedError } | |
| define_method(:"#{param}=") { raise NotImplementedError } | |
| end | |
| def initialize(options = {}) | |
| PARAMS.each do |param| | |
| public_send(:"#{param}=", options[param]) | |
| end | |
| end | |
| end | |
| class LessonTile | |
| def self.build(user) | |
| completed_count = Lesson.completed_by(user).count | |
| total_count = Lesson.for(user.default_locale).count | |
| DashboardTile.new({ | |
| image: 'learn/lessons.png', | |
| name: 'Lessons', | |
| description: 'Learn how to use the Twitter Translation Center '\ | |
| 'and create better translations.', | |
| count: "#{completed_count}/#{total_count}", | |
| count_suffix: 'COMPLETE', | |
| status: completed_count == 0 ? 'Get Started' : 'Continue', | |
| url: lessons_path, | |
| url_class: completed_count >= total_count ? 'disabled' : '', | |
| }) | |
| end | |
| end | |
| class FeedbackTile | |
| def self.build(user) | |
| feedback_count = TranslationFeedback.incomplete_for(user).count | |
| DashboardTile.new({ | |
| image: 'learn/feedback.png', | |
| name: 'Feedback', | |
| description: 'Which translation do you think is approved for the given phrase?', | |
| count: feedback_count.to_s, | |
| count_suffix: 'AVAILABLE', | |
| status: 'Get Started', | |
| url: translation_feedbacks_path, | |
| url_class: feedback_count == 0 ? 'disabled' : '', | |
| }) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://reviewboard.twitter.biz/r/178997/diff/1/?file=5680633#file5680633line3