configurable link hint text & url

stable
Juanfran 2015-06-12 10:28:12 +02:00
parent 21f705a0e8
commit a072d96eac
3 changed files with 24 additions and 30 deletions

View File

@ -1,21 +1,28 @@
class ProfileHints class ProfileHints
maxHints: 4 HINTS: [
supportUrls: [ { #hint1
"https://taiga.io/support/import-export-projects/", #HINT1 url: "https://taiga.io/support/import-export-projects/"
"https://taiga.io/support/custom-fields/" #HINT2 },
"#" #HINT3 { #hint2
"#" #HINT4 url: "https://taiga.io/support/custom-fields/"
},
{ #hint3
},
{ #hint4
}
] ]
constructor: (@translate) -> constructor: (@translate) ->
hintKey = Math.floor(Math.random() * @.maxHints) + 1 hintKey = Math.floor(Math.random() * @.HINTS.length) + 1
@.url = @.supportUrls[hintKey - 1] @.hint = @.HINTS[hintKey - 1]
@.hint.linkText = @.hint.linkText || 'HINTS.LINK'
@translate("HINTS.HINT#{hintKey}_TITLE").then (text) => @translate("HINTS.HINT#{hintKey}_TITLE").then (text) =>
@.title = text @.hint.title = text
@translate("HINTS.HINT#{hintKey}_TEXT").then (text) => @translate("HINTS.HINT#{hintKey}_TEXT").then (text) =>
@.text = text @.hint.text = text
ProfileHints.$inject = [ ProfileHints.$inject = [
"$translate" "$translate"

View File

@ -24,26 +24,13 @@ describe "ProfileHints", ->
$controller = _$controller_ $controller = _$controller_
it "random hint generator", (done) -> it "random hint generator", (done) ->
mocks.translateService.promise().resolve("fill")
returned = {
then: () ->
}
mocks.translateService.withArgs("HINTS.HINT1_TITLE").promise().resolve("title_1")
mocks.translateService.withArgs("HINTS.HINT1_TEXT").promise().resolve("text_1")
mocks.translateService.withArgs("HINTS.HINT2_TITLE").promise().resolve("title_2")
mocks.translateService.withArgs("HINTS.HINT2_TEXT").promise().resolve("text_2")
ctrl = $controller("ProfileHints") ctrl = $controller("ProfileHints")
setTimeout ( -> setTimeout ( ->
if ctrl.url == "https://taiga.io/support/custom-fields/" expect(ctrl.hint.title).to.be.equal("fill")
expect(ctrl.title).to.be.equal("title_2") expect(ctrl.hint.text).to.be.equal("fill")
expect(ctrl.text).to.be.equal("text_2") expect(ctrl.hint.linkText).to.have.length.above(1)
done()
else if ctrl.url == "https://taiga.io/support/import-export-projects/"
expect(ctrl.title).to.be.equal("title_1")
expect(ctrl.text).to.be.equal("text_1")
done() done()
) )

View File

@ -2,7 +2,7 @@ h4
span.icon.icon-help span.icon.icon-help
span(translate="HINTS.SECTION_NAME") span(translate="HINTS.SECTION_NAME")
p {{::vm.title}} p {{::vm.hint.title}}
p {{::vm.text}} p {{::vm.hint.text}}
|   |  
a(target="_blank", ng-href="{{::vm.url}}", title="{{'HINTS.LINK_TITLE' | translate}}", translate="HINTS.LINK") a(ng-if="::vm.hint.url", target="_blank", ng-href="{{::vm.hint.url}}", title="{{'HINTS.LINK_TITLE' | translate}}", translate="{{::vm.hint.linkText}}")