coffescript refactoring pt.1
This commit is contained in:
parent
37f3d0f25b
commit
0b981eb9b3
|
@ -1,5 +1,6 @@
|
|||
@Commit =
|
||||
init: ->
|
||||
class Commit
|
||||
constructor: ->
|
||||
$('.files .file').each ->
|
||||
new CommitFile(this)
|
||||
|
||||
@Commit = Commit
|
||||
|
|
|
@ -1,39 +1,44 @@
|
|||
window.dashboardPage = ->
|
||||
Pager.init 20, true
|
||||
initSidebarTab()
|
||||
$(".event_filter_link").bind "click", (event) ->
|
||||
event.preventDefault()
|
||||
toggleFilter $(this)
|
||||
reloadActivities()
|
||||
class Dashboard
|
||||
constructor: ->
|
||||
Pager.init 20, true
|
||||
@initSidebarTab()
|
||||
|
||||
reloadActivities = ->
|
||||
$(".content_list").html ''
|
||||
Pager.init 20, true
|
||||
$(".event_filter_link").bind "click", (event) =>
|
||||
event.preventDefault()
|
||||
@toggleFilter($(event.currentTarget))
|
||||
@reloadActivities()
|
||||
|
||||
toggleFilter = (sender) ->
|
||||
sender.parent().toggleClass "inactive"
|
||||
event_filters = $.cookie("event_filter")
|
||||
filter = sender.attr("id").split("_")[0]
|
||||
if event_filters
|
||||
event_filters = event_filters.split(",")
|
||||
else
|
||||
event_filters = new Array()
|
||||
reloadActivities: ->
|
||||
$(".content_list").html ''
|
||||
Pager.init 20, true
|
||||
|
||||
index = event_filters.indexOf(filter)
|
||||
if index is -1
|
||||
event_filters.push filter
|
||||
else
|
||||
event_filters.splice index, 1
|
||||
toggleFilter: (sender) ->
|
||||
sender.parent().toggleClass "inactive"
|
||||
event_filters = $.cookie("event_filter")
|
||||
filter = sender.attr("id").split("_")[0]
|
||||
if event_filters
|
||||
event_filters = event_filters.split(",")
|
||||
else
|
||||
event_filters = new Array()
|
||||
|
||||
$.cookie "event_filter", event_filters.join(",")
|
||||
index = event_filters.indexOf(filter)
|
||||
if index is -1
|
||||
event_filters.push filter
|
||||
else
|
||||
event_filters.splice index, 1
|
||||
|
||||
initSidebarTab = ->
|
||||
key = "dashboard_sidebar_filter"
|
||||
$.cookie "event_filter", event_filters.join(",")
|
||||
|
||||
# store selection in cookie
|
||||
$('.dash-sidebar-tabs a').on 'click', (e) ->
|
||||
$.cookie(key, $(e.target).attr('id'))
|
||||
initSidebarTab: ->
|
||||
key = "dashboard_sidebar_filter"
|
||||
|
||||
# show tab from cookie
|
||||
sidebar_filter = $.cookie(key)
|
||||
$("#" + sidebar_filter).tab('show') if sidebar_filter
|
||||
# store selection in cookie
|
||||
$('.dash-sidebar-tabs a').on 'click', (e) ->
|
||||
$.cookie(key, $(e.target).attr('id'))
|
||||
|
||||
# show tab from cookie
|
||||
sidebar_filter = $.cookie(key)
|
||||
$("#" + sidebar_filter).tab('show') if sidebar_filter
|
||||
|
||||
|
||||
@Dashboard = Dashboard
|
||||
|
|
|
@ -4,16 +4,27 @@ $ ->
|
|||
class Dispatcher
|
||||
constructor: () ->
|
||||
page = $('body').attr('data-page')
|
||||
project_id = $('body').attr('data-project-id')
|
||||
|
||||
console.log(page)
|
||||
|
||||
path = page.split(':')
|
||||
|
||||
switch page
|
||||
when 'issues:index' then Issues.init()
|
||||
when 'dashboard:show' then dashboardPage()
|
||||
when 'commit:show' then Commit.init()
|
||||
when 'issues:index'
|
||||
Issues.init()
|
||||
when 'dashboard:show'
|
||||
new Dashboard()
|
||||
when 'commit:show'
|
||||
new Commit()
|
||||
when 'groups:show', 'teams:show', 'projects:show'
|
||||
Pager.init(20, true)
|
||||
when 'projects:new', 'projects:edit'
|
||||
new Projects()
|
||||
when 'admin:teams:show', 'admin:groups:show', 'admin:logs:show', 'admin:users:new'
|
||||
Admin.init()
|
||||
new Project()
|
||||
when 'walls:show'
|
||||
new Wall(project_id)
|
||||
|
||||
switch path.first()
|
||||
when 'admin' then Admin.init()
|
||||
when 'wikis' then new Wikis()
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
class Project
|
||||
constructor: ->
|
||||
$('.new_project, .edit_project').on 'ajax:before', ->
|
||||
$('.project_new_holder, .project_edit_holder').hide()
|
||||
$('.save-project-loader').show()
|
||||
|
||||
$('form #project_default_branch').chosen()
|
||||
disableButtonIfEmptyField '#project_name', '.project-submit'
|
||||
|
||||
$('#project_issues_enabled').change ->
|
||||
if ($(this).is(':checked') == true)
|
||||
$('#project_issues_tracker').removeAttr('disabled')
|
||||
else
|
||||
$('#project_issues_tracker').attr('disabled', 'disabled')
|
||||
|
||||
$('#project_issues_tracker').change()
|
||||
|
||||
$('#project_issues_tracker').change ->
|
||||
if ($(this).val() == gon.default_issues_tracker || $(this).is(':disabled'))
|
||||
$('#project_issues_tracker_id').attr('disabled', 'disabled')
|
||||
else
|
||||
$('#project_issues_tracker_id').removeAttr('disabled')
|
||||
|
||||
@Project = Project
|
||||
|
||||
$ ->
|
||||
# Git clone panel switcher
|
||||
scope = $ '.project_clone_holder'
|
||||
if scope.length > 0
|
||||
$('a, button', scope).click ->
|
||||
$('a, button', scope).removeClass 'active'
|
||||
$(@).addClass 'active'
|
||||
$('#project_clone', scope).val $(@).data 'clone'
|
||||
|
||||
# Ref switcher
|
||||
$('.project-refs-select').on 'change', ->
|
||||
$(@).parents('form').submit()
|
|
@ -1,35 +0,0 @@
|
|||
window.Projects = ->
|
||||
$('.new_project, .edit_project').on 'ajax:before', ->
|
||||
$('.project_new_holder, .project_edit_holder').hide()
|
||||
$('.save-project-loader').show()
|
||||
|
||||
$('form #project_default_branch').chosen()
|
||||
disableButtonIfEmptyField '#project_name', '.project-submit'
|
||||
|
||||
$ ->
|
||||
# Git clone panel switcher
|
||||
scope = $ '.project_clone_holder'
|
||||
if scope.length > 0
|
||||
$('a, button', scope).click ->
|
||||
$('a, button', scope).removeClass 'active'
|
||||
$(@).addClass 'active'
|
||||
$('#project_clone', scope).val $(@).data 'clone'
|
||||
|
||||
# Ref switcher
|
||||
$('.project-refs-select').on 'change', ->
|
||||
$(@).parents('form').submit()
|
||||
|
||||
$('#project_issues_enabled').change ->
|
||||
if ($(this).is(':checked') == true)
|
||||
$('#project_issues_tracker').removeAttr('disabled')
|
||||
else
|
||||
$('#project_issues_tracker').attr('disabled', 'disabled')
|
||||
|
||||
$('#project_issues_tracker').change()
|
||||
|
||||
$('#project_issues_tracker').change ->
|
||||
if ($(this).val() == gon.default_issues_tracker || $(this).is(':disabled'))
|
||||
$('#project_issues_tracker_id').attr('disabled', 'disabled')
|
||||
else
|
||||
$('#project_issues_tracker_id').removeAttr('disabled')
|
||||
|
|
@ -1,32 +1,32 @@
|
|||
@Wall =
|
||||
note_ids: []
|
||||
project_id: null
|
||||
|
||||
init: (project_id) ->
|
||||
Wall.project_id = project_id
|
||||
Wall.getContent()
|
||||
Wall.initRefresh()
|
||||
Wall.initForm()
|
||||
class Wall
|
||||
constructor: (project_id) ->
|
||||
@project_id = project_id
|
||||
@note_ids = []
|
||||
@getContent()
|
||||
@initRefresh()
|
||||
@initForm()
|
||||
|
||||
#
|
||||
# Gets an initial set of notes.
|
||||
#
|
||||
getContent: ->
|
||||
Api.notes Wall.project_id, (notes) ->
|
||||
$.each notes, (i, note) ->
|
||||
Api.notes @project_id, (notes) =>
|
||||
$.each notes, (i, note) =>
|
||||
# render note if it not present in loaded list
|
||||
# or skip if rendered
|
||||
if $.inArray(note.id, Wall.note_ids) == -1
|
||||
Wall.note_ids.push(note.id)
|
||||
Wall.renderNote(note)
|
||||
Wall.scrollDown()
|
||||
if $.inArray(note.id, @note_ids) == -1
|
||||
@note_ids.push(note.id)
|
||||
@renderNote(note)
|
||||
@scrollDown()
|
||||
$("abbr.timeago").timeago()
|
||||
|
||||
initRefresh: ->
|
||||
setInterval("Wall.refresh()", 10000)
|
||||
setInterval =>
|
||||
@refresh()
|
||||
, 10000
|
||||
|
||||
refresh: ->
|
||||
Wall.getContent()
|
||||
@getContent()
|
||||
|
||||
scrollDown: ->
|
||||
notes = $('ul.notes')
|
||||
|
@ -36,8 +36,8 @@
|
|||
form = $('.wall-note-form')
|
||||
form.find("#target_type").val('wall')
|
||||
|
||||
form.on 'ajax:success', ->
|
||||
Wall.refresh()
|
||||
form.on 'ajax:success', =>
|
||||
@refresh()
|
||||
form.find(".js-note-text").val("").trigger("input")
|
||||
|
||||
form.on 'ajax:complete', ->
|
||||
|
@ -58,7 +58,7 @@
|
|||
form.show()
|
||||
|
||||
renderNote: (note) ->
|
||||
template = Wall.noteTemplate()
|
||||
template = @noteTemplate()
|
||||
template = template.replace('{{author_name}}', note.author.name)
|
||||
template = template.replace('{{created_at}}', note.created_at)
|
||||
template = template.replace('{{text}}', linkify(sanitize(note.body)))
|
||||
|
@ -81,3 +81,5 @@
|
|||
</span>
|
||||
<abbr class="timeago" title="{{created_at}}">{{created_at}}</abbr>
|
||||
</li>'
|
||||
|
||||
@Wall = Wall
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
class Wikis
|
||||
constructor: ->
|
||||
modal = $('#modal-new-wiki').modal({modal: true, show:false})
|
||||
|
||||
$('.add-new-wiki').bind "click", ->
|
||||
modal.show()
|
||||
|
||||
$('.build-new-wiki').bind "click", ->
|
||||
field = $('#new_wiki_path')
|
||||
slug = field.val()
|
||||
path = field.attr('data-wikis-path')
|
||||
|
||||
if(slug.length > 0)
|
||||
location.href = path + "/" + slug
|
||||
|
||||
$('.modal-header .close').bind "click", ->
|
||||
modal.hide()
|
||||
|
||||
@Wikis = Wikis
|
|
@ -7,11 +7,10 @@
|
|||
|
||||
:javascript
|
||||
var branch_graph;
|
||||
$(function(){
|
||||
branch_graph = new BranchGraph($("#holder"), {
|
||||
url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}',
|
||||
commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}',
|
||||
ref: '#{@ref}',
|
||||
commit_id: '#{@commit.id}'
|
||||
});
|
||||
|
||||
branch_graph = new BranchGraph($("#holder"), {
|
||||
url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}',
|
||||
commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}',
|
||||
ref: '#{@ref}',
|
||||
commit_id: '#{@commit.id}'
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
!!! 5
|
||||
%html{ lang: "en"}
|
||||
= render "layouts/head", title: @project.name_with_namespace
|
||||
%body{class: "#{app_theme} project", :'data-page' => body_data_page}
|
||||
%body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id }
|
||||
= render "layouts/head_panel", title: project_title(@project)
|
||||
= render "layouts/flash"
|
||||
- if can?(current_user, :download_code, @project)
|
||||
|
|
|
@ -26,14 +26,12 @@
|
|||
|
||||
:javascript
|
||||
var merge_request;
|
||||
$(function(){
|
||||
merge_request = new MergeRequest({
|
||||
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
|
||||
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
|
||||
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
|
||||
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
|
||||
current_status: "#{@merge_request.merge_status_name}",
|
||||
action: "#{controller.action_name}"
|
||||
});
|
||||
});
|
||||
|
||||
merge_request = new MergeRequest({
|
||||
url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
|
||||
check_enable: #{@merge_request.unchecked? ? "true" : "false"},
|
||||
url_to_ci_check: "#{ci_status_project_merge_request_path(@project, @merge_request)}",
|
||||
ci_enable: #{@project.gitlab_ci? ? "true" : "false"},
|
||||
current_status: "#{@merge_request.merge_status_name}",
|
||||
action: "#{controller.action_name}"
|
||||
});
|
||||
|
|
|
@ -21,8 +21,3 @@
|
|||
|
||||
.hint.pull-right CTRL + Enter to send message
|
||||
.clearfix
|
||||
|
||||
:javascript
|
||||
$(function(){
|
||||
Wall.init(#{@project.id});
|
||||
});
|
||||
|
|
|
@ -5,27 +5,8 @@
|
|||
.modal-body
|
||||
= label_tag :new_wiki_path do
|
||||
%span Page slug
|
||||
= text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'input-xlarge', required: true
|
||||
= text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'input-xlarge', required: true, :'data-wikis-path' => project_wikis_path(@project)
|
||||
%p.hint
|
||||
Please dont use spaces and slashes
|
||||
.modal-footer
|
||||
= link_to 'Build', '#', class: 'build-new-wiki btn btn-create'
|
||||
|
||||
:javascript
|
||||
$(function(){
|
||||
var modal = $('#modal-new-wiki').modal({modal: true, show:false});
|
||||
$('.add-new-wiki').bind("click", function(){
|
||||
modal.show();
|
||||
});
|
||||
$('.build-new-wiki').bind("click", function(){
|
||||
var slug = $('#new_wiki_path').val();
|
||||
|
||||
if(slug.length > 0) {
|
||||
location.href = "#{project_wikis_path(@project)}/" + slug;
|
||||
}
|
||||
});
|
||||
$('.modal-header .close').bind("click", function(){
|
||||
modal.hide();
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue