github form integration
parent
b8bf8902d1
commit
1129469cce
|
@ -57,6 +57,10 @@ class GithubController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
|
||||||
|
|
||||||
promise.then null, @.onInitialDataError.bind(@)
|
promise.then null, @.onInitialDataError.bind(@)
|
||||||
|
|
||||||
|
loadModules: ->
|
||||||
|
return @rs.modules.list(@scope.projectId, "github").then (github) =>
|
||||||
|
@scope.github = github
|
||||||
|
|
||||||
loadProject: ->
|
loadProject: ->
|
||||||
return @rs.projects.get(@scope.projectId).then (project) =>
|
return @rs.projects.get(@scope.projectId).then (project) =>
|
||||||
@scope.project = project
|
@scope.project = project
|
||||||
|
@ -71,11 +75,11 @@ class GithubController extends mixOf(taiga.Controller, taiga.PageMixin, taiga.Fi
|
||||||
return data
|
return data
|
||||||
|
|
||||||
return promise.then(=> @.loadProject())
|
return promise.then(=> @.loadProject())
|
||||||
|
.then(=> @.loadModules())
|
||||||
|
|
||||||
|
|
||||||
module.controller("GithubController", GithubController)
|
module.controller("GithubController", GithubController)
|
||||||
|
|
||||||
|
|
||||||
SelectInputText = ->
|
SelectInputText = ->
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
$el.on "click", ".select-input-content", () ->
|
$el.on "click", ".select-input-content", () ->
|
||||||
|
@ -85,3 +89,40 @@ SelectInputText = ->
|
||||||
return {link:link}
|
return {link:link}
|
||||||
|
|
||||||
module.directive("tgSelectInputText", SelectInputText)
|
module.directive("tgSelectInputText", SelectInputText)
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## GithubWebhooks Directive
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
GithubWebhooksDirective = ($repo, $confirm, $loading, $navurls, $location) ->
|
||||||
|
link = ($scope, $el, $attrs) ->
|
||||||
|
form = $el.find("form").checksley({"onlyOneErrorElement": true})
|
||||||
|
submit = (target) =>
|
||||||
|
return if not form.validate()
|
||||||
|
|
||||||
|
$loading.start(target)
|
||||||
|
|
||||||
|
promise = $repo.saveAttribute($scope.github, "github")
|
||||||
|
promise.then ->
|
||||||
|
$loading.finish(target)
|
||||||
|
$confirm.notify("success")
|
||||||
|
|
||||||
|
promise.then null, (data) ->
|
||||||
|
$loading.finish(target)
|
||||||
|
form.setErrors(data)
|
||||||
|
if data._error_message
|
||||||
|
$confirm.notify("error", data._error_message)
|
||||||
|
|
||||||
|
|
||||||
|
$el.on "click", "a.button-green", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
target = angular.element(event.currentTarget)
|
||||||
|
submit(target)
|
||||||
|
|
||||||
|
$el.on "submit", "form", (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
submit()
|
||||||
|
|
||||||
|
return {link:link}
|
||||||
|
|
||||||
|
module.directive("tgGithubWebhooks", ["$tgRepo", "$tgConfirm", "$tgLoading", "$tgNavUrls", "$tgLocation", GithubWebhooksDirective])
|
||||||
|
|
|
@ -28,8 +28,11 @@ class RepositoryService extends taiga.Service
|
||||||
super()
|
super()
|
||||||
|
|
||||||
resolveUrlForModel: (model) ->
|
resolveUrlForModel: (model) ->
|
||||||
idAttrName = model.getIdAttrName()
|
if model.parent
|
||||||
return "#{@urls.resolve(model.getName())}/#{model[idAttrName]}"
|
return @urls.resolve(model.getName(), model.parent)
|
||||||
|
else
|
||||||
|
idAttrName = model.getIdAttrName()
|
||||||
|
return "#{@urls.resolve(model.getName())}/#{model[idAttrName]}"
|
||||||
|
|
||||||
create: (name, data, dataTypes={}, extraParams={}) ->
|
create: (name, data, dataTypes={}, extraParams={}) ->
|
||||||
defered = @q.defer()
|
defered = @q.defer()
|
||||||
|
@ -89,6 +92,37 @@ class RepositoryService extends taiga.Service
|
||||||
|
|
||||||
return defered.promise
|
return defered.promise
|
||||||
|
|
||||||
|
saveAttribute: (model, attribute, patch=true) ->
|
||||||
|
defered = @q.defer()
|
||||||
|
|
||||||
|
if not model.isModified() and patch
|
||||||
|
defered.resolve(model)
|
||||||
|
return defered.promise
|
||||||
|
|
||||||
|
url = @.resolveUrlForModel(model)
|
||||||
|
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
data[attribute] = model.getAttrs()
|
||||||
|
|
||||||
|
if patch
|
||||||
|
promise = @http.patch(url, data)
|
||||||
|
else
|
||||||
|
promise = @http.put(url, data)
|
||||||
|
|
||||||
|
promise.success (data, status) =>
|
||||||
|
model._isModified = false
|
||||||
|
model._attrs = _.extend(model.getAttrs(), data)
|
||||||
|
model._modifiedAttrs = {}
|
||||||
|
|
||||||
|
model.applyCasts()
|
||||||
|
defered.resolve(model)
|
||||||
|
|
||||||
|
promise.error (data, status) ->
|
||||||
|
defered.reject(data)
|
||||||
|
|
||||||
|
return defered.promise
|
||||||
|
|
||||||
refresh: (model) ->
|
refresh: (model) ->
|
||||||
defered = @q.defer()
|
defered = @q.defer()
|
||||||
|
|
||||||
|
@ -115,6 +149,19 @@ class RepositoryService extends taiga.Service
|
||||||
return @http.get(url, params, httpOptions).then (data) =>
|
return @http.get(url, params, httpOptions).then (data) =>
|
||||||
return _.map(data.data, (x) => @model.make_model(name, x))
|
return _.map(data.data, (x) => @model.make_model(name, x))
|
||||||
|
|
||||||
|
queryOneAttribute: (name, id, attribute, params, options={}) ->
|
||||||
|
url = @urls.resolve(name, id)
|
||||||
|
httpOptions = {headers: {}}
|
||||||
|
|
||||||
|
if not options.enablePagination
|
||||||
|
httpOptions.headers["x-disable-pagination"] = "1"
|
||||||
|
|
||||||
|
return @http.get(url, params, httpOptions).then (data) =>
|
||||||
|
model = @model.make_model(name, data.data[attribute])
|
||||||
|
model.parent = id
|
||||||
|
|
||||||
|
return model
|
||||||
|
|
||||||
queryOne: (name, id, params, options={}) ->
|
queryOne: (name, id, params, options={}) ->
|
||||||
url = @urls.resolve(name)
|
url = @urls.resolve(name)
|
||||||
url = "#{url}/#{id}" if id
|
url = "#{url}/#{id}" if id
|
||||||
|
|
|
@ -83,6 +83,7 @@ urls = {
|
||||||
"issue-types": "/issue-types"
|
"issue-types": "/issue-types"
|
||||||
"priorities": "/priorities"
|
"priorities": "/priorities"
|
||||||
"severities": "/severities"
|
"severities": "/severities"
|
||||||
|
"project-modules": "/projects/%s/modules"
|
||||||
|
|
||||||
# History
|
# History
|
||||||
"history/us": "/history/userstory"
|
"history/us": "/history/userstory"
|
||||||
|
@ -138,5 +139,6 @@ module.run([
|
||||||
"$tgMdRenderResourcesProvider",
|
"$tgMdRenderResourcesProvider",
|
||||||
"$tgHistoryResourcesProvider",
|
"$tgHistoryResourcesProvider",
|
||||||
"$tgKanbanResourcesProvider",
|
"$tgKanbanResourcesProvider",
|
||||||
|
"$tgModulesResourcesProvider",
|
||||||
initResources
|
initResources
|
||||||
])
|
])
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
resourceProvider = ($repo) ->
|
||||||
|
service = {}
|
||||||
|
|
||||||
|
service.list = (projectId, module) ->
|
||||||
|
return $repo.queryOneAttribute("project-modules", projectId, module)
|
||||||
|
|
||||||
|
return (instance) ->
|
||||||
|
instance.modules = service
|
||||||
|
|
||||||
|
|
||||||
|
module = angular.module("taigaResources")
|
||||||
|
module.factory("$tgModulesResourcesProvider", ["$tgRepo", resourceProvider])
|
|
@ -2,7 +2,7 @@ block head
|
||||||
title Taiga Your agile, free, and open source project management tool
|
title Taiga Your agile, free, and open source project management tool
|
||||||
|
|
||||||
block content
|
block content
|
||||||
div.wrapper.roles(ng-controller="GithubController as ctrl",
|
div.wrapper.roles(tg-github-webhooks, ng-controller="GithubController as ctrl",
|
||||||
ng-init="section='admin'")
|
ng-init="section='admin'")
|
||||||
sidebar.menu-secondary.sidebar(tg-admin-navigation="third-parties")
|
sidebar.menu-secondary.sidebar(tg-admin-navigation="third-parties")
|
||||||
include views/modules/admin-menu
|
include views/modules/admin-menu
|
||||||
|
@ -15,14 +15,14 @@ block content
|
||||||
form
|
form
|
||||||
fieldset
|
fieldset
|
||||||
label(for="secret-key") Secret key
|
label(for="secret-key") Secret key
|
||||||
input(type="text", name="secret-key", placeholder="Secret key", id="secret-key")
|
input(type="text", name="secret-key", ng-model="github.secret", placeholder="Secret key", id="secret-key")
|
||||||
|
|
||||||
fieldset
|
fieldset
|
||||||
.select-input-text(tg-select-input-text)
|
.select-input-text(tg-select-input-text)
|
||||||
div
|
div
|
||||||
label(for="payload-url") Payload URL
|
label(for="payload-url") Payload URL
|
||||||
.field-with-option
|
.field-with-option
|
||||||
input(type="text", name="payload-url", readonly="readonly", placeholder="Payload URL", id="payload-url")
|
input(type="text", ng-model="github.webhooks_url", name="payload-url", readonly="readonly", placeholder="Payload URL", id="payload-url")
|
||||||
.option-wrapper.select-input-content
|
.option-wrapper.select-input-content
|
||||||
.icon.icon-copy
|
.icon.icon-copy
|
||||||
.help-copy Copy to clipboard: Ctrl+C
|
.help-copy Copy to clipboard: Ctrl+C
|
||||||
|
@ -49,9 +49,7 @@ block content
|
||||||
li Click on
|
li Click on
|
||||||
span Settings
|
span Settings
|
||||||
| >
|
| >
|
||||||
span Webhooks
|
span Webhooks & Services
|
||||||
| >
|
|
||||||
span Services
|
|
||||||
| >
|
| >
|
||||||
span Add webhook
|
span Add webhook
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue