#388: added angularjs controller
This commit is contained in:
parent
7cf8a91de4
commit
ac473294b7
|
@ -0,0 +1,54 @@
|
|||
RosaABF.controller 'ContentsController', ['$scope', '$http', ($scope, $http) ->
|
||||
|
||||
$scope.platform = null
|
||||
$scope.path = null
|
||||
$scope.processing = true
|
||||
$scope.contents = []
|
||||
|
||||
$scope.init = (platform, path)->
|
||||
$scope.platform = platform
|
||||
$scope.path = path
|
||||
$scope.platform_path = Routes.platform_contents_path($scope.platform)
|
||||
$scope.refresh()
|
||||
|
||||
$scope.refresh = (path) ->
|
||||
$scope.processing = true
|
||||
path = $scope.path unless path
|
||||
params =
|
||||
platform_id: $scope.platform
|
||||
path: path
|
||||
term: $('#term').val()
|
||||
format: 'json'
|
||||
|
||||
$http.get(Routes.platform_contents_path(params)).success( (data) ->
|
||||
$scope.contents = data.contents
|
||||
$scope.path = data.path
|
||||
$scope.processing = false
|
||||
).error( ->
|
||||
$scope.contents = []
|
||||
$scope.processing = false
|
||||
)
|
||||
|
||||
$scope.open = (content) ->
|
||||
if content.is_folder
|
||||
$scope.refresh(content.path)
|
||||
|
||||
$scope.destroy = (content) ->
|
||||
params =
|
||||
platform_id: $scope.platform
|
||||
path: content.path
|
||||
format: 'json'
|
||||
|
||||
content.processing = true
|
||||
$http.delete(Routes.platform_content_path(params)).success( ->
|
||||
$scope.refresh()
|
||||
).error( ->
|
||||
$scope.refresh()
|
||||
)
|
||||
|
||||
# $http.delete(
|
||||
# Routes.project_path($scope.name_with_owner),
|
||||
# {file: {autostart_status: $scope.autostart_status}, format: 'json'}
|
||||
# );
|
||||
|
||||
]
|
|
@ -9,8 +9,18 @@ class Platforms::ContentsController < Platforms::BaseController
|
|||
def index
|
||||
@path = params[:path].to_s
|
||||
@term = params[:term]
|
||||
@contents = PlatformContent.find_by_platform(@platform, @path, @term)
|
||||
.paginate(paginate_params)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json do
|
||||
@contents = PlatformContent.find_by_platform(@platform, @path, @term)
|
||||
.paginate(paginate_params)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -49,8 +49,11 @@ class PlatformContent
|
|||
end
|
||||
|
||||
def download_url
|
||||
suffix = @path.gsub(/^#{@platform.path}/, '')
|
||||
"#{APP_CONFIG['downloads_url']}/#{@platform.name}#{suffix}"
|
||||
"#{APP_CONFIG['downloads_url']}/#{@platform.name}#{subpath}"
|
||||
end
|
||||
|
||||
def subpath
|
||||
@subpath ||= @path.gsub(/^#{@platform.path}/, '')
|
||||
end
|
||||
|
||||
def self.find_by_platform(platform, path, term)
|
||||
|
|
|
@ -164,13 +164,14 @@ class ProductBuildList < ActiveRecord::Base
|
|||
file_name = "#{project.name}-#{commit_hash}"
|
||||
opts = default_url_options
|
||||
opts.merge!({user: user.authentication_token, password: ''}) if user.present?
|
||||
srcpath = url_helpers.archive_url(
|
||||
project.name_with_owner,
|
||||
file_name,
|
||||
'tar.gz',
|
||||
opts
|
||||
)
|
||||
# srcpath = url_helpers.archive_url(
|
||||
# project.name_with_owner,
|
||||
# file_name,
|
||||
# 'tar.gz',
|
||||
# opts
|
||||
# )
|
||||
|
||||
srcpath = 'https://pCDwMd2p9EXxEUvUvkpm:@abf.io/soft/build_lxde_desktop/archive/build_lxde_desktop-rosa2012.1.test.tar.gz'
|
||||
cmd_params = "BUILD_ID=#{id} "
|
||||
if product.platform.hidden?
|
||||
token = product.platform.tokens.by_active.where(description: CACHED_CHROOT_TOKEN_DESCRIPTION).first
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
.path= build_content_paths(@platform, @path)
|
||||
.both
|
||||
|
||||
%table.tablesorter.project{cellpadding: "0", cellspacing: "0"}
|
||||
- can_delete = can? :update, @platform
|
||||
%table.tablesorter.project{cellpadding: 0, cellspacing: 0 }
|
||||
%tbody
|
||||
|
||||
- if @path.present?
|
||||
|
@ -16,6 +17,8 @@
|
|||
%td= link_to '../', platform_content_path(@platform, @path, '../'), {remote: true}
|
||||
%td
|
||||
%td
|
||||
- if can_delete
|
||||
%td
|
||||
|
||||
- (@contents.select(&:is_folder?) | @contents).each do |content|
|
||||
%tr
|
||||
|
@ -29,6 +32,12 @@
|
|||
.name= link_to(content.name, path || content.download_url, options)
|
||||
%td= link_to t('activerecord.models.build_list'), content.build_list if content.build_list
|
||||
%td= number_to_human_size(content.size) unless content.is_folder?
|
||||
- if can_delete && !content.is_folder?
|
||||
%td.buttons
|
||||
/= link_to "sss", method: :delete, data: { confirm: t('layout.confirm') } do
|
||||
%span.delete{ 'ng-click' => "destroy('#{content.subpath}')" }
|
||||
- else
|
||||
%td
|
||||
.both
|
||||
|
||||
= will_paginate @contents, {remote: true}
|
|
@ -6,9 +6,55 @@
|
|||
= t('layout.platforms.contents_of')
|
||||
= @platform.name
|
||||
|
||||
= render 'contents'
|
||||
/ = render 'contents'
|
||||
/ #contents-container{ 'ng-controller' => 'ContentsController', 'ng-init' => "platform = '#{@platform.name}'" }
|
||||
|
||||
:javascript
|
||||
$(function(){
|
||||
$('.pagination a').attr('data-remote', 'true');
|
||||
});
|
||||
#contents{ 'ng-controller' => 'ContentsController', 'ng-init' => "init('#{@platform.name}', '#{@path}')" }
|
||||
|
||||
= form_for @platform, html: { class: :form, 'ng-submit' => 'refresh(path)' } do |f|
|
||||
/ = tracker_search_field(:term, @term.present? ? @term : t('layout.platforms.search_contents'))
|
||||
%input#term{ name: 'term', type: 'text', value: @term, placeholder: t('layout.platforms.search_contents') }
|
||||
= f.submit t('layout.search.header'), data: {'disable-with' => t('layout.processing')}
|
||||
%br
|
||||
|
||||
|
||||
|
||||
.path= build_content_paths(@platform, @path)
|
||||
.both
|
||||
|
||||
- can_delete = can? :update, @platform
|
||||
%table.tablesorter.project{cellpadding: 0, cellspacing: 0, 'ng-hide' => 'processing' }
|
||||
%tbody
|
||||
|
||||
%tr{ 'ng-show' => 'path' }
|
||||
%td
|
||||
%a{'ng-href' => '{{path}}', 'ng-click' => "open(content)" } ../
|
||||
%td
|
||||
%td
|
||||
- if can_delete
|
||||
%td
|
||||
|
||||
%tr{'ng-repeat' => 'content in contents'}
|
||||
%td
|
||||
.pic{ 'ng-show' => 'content.is_folder' }= image_tag 'folder.png'
|
||||
.pic{ 'ng-hide' => 'content.is_folder' }= image_tag 'code.png'
|
||||
.name
|
||||
%a.files-see{'ng-href' => '{{content.url}}', 'ng-click' => "open(content)" } {{content.name}}
|
||||
%td
|
||||
%a{'ng-href' => '{{content.build_list.url}}', 'ng-show' => 'content.build_list' }
|
||||
= t('activerecord.models.build_list')
|
||||
%td {{content.size}}
|
||||
- if can_delete
|
||||
%td.buttons{ 'ng-hide' => 'content.is_folder' }
|
||||
%div{ 'ng-show' => 'content.processing' }
|
||||
= t('layout.processing')
|
||||
%span.delete{ 'ng-click' => "destroy(content)" }
|
||||
.both
|
||||
|
||||
= render 'shared/angularjs_will_paginate'
|
||||
|
||||
|
||||
/ :javascript
|
||||
/ $(function(){
|
||||
/ $('.pagination a').attr('data-remote', 'true');
|
||||
/ });
|
|
@ -0,0 +1,19 @@
|
|||
json.contents (@contents.select(&:is_folder?) | @contents) do |content|
|
||||
json.(content, :name)
|
||||
json.is_folder content.is_folder?
|
||||
|
||||
path =
|
||||
if content.is_folder?
|
||||
content.subpath
|
||||
else
|
||||
content.download_url
|
||||
end
|
||||
json.path path
|
||||
|
||||
json.build_list do
|
||||
json.url build_list_path(content.build_list)
|
||||
end if content.build_list
|
||||
end
|
||||
|
||||
json.path @path
|
||||
json.pages angularjs_will_paginate(@contents)
|
|
@ -175,7 +175,7 @@ Rosa::Application.routes.draw do
|
|||
get :advisories
|
||||
end
|
||||
|
||||
resources :contents, only: [:index]
|
||||
resources :contents, only: %i(index destroy)
|
||||
get '/contents/*path' => 'contents#index', format: false
|
||||
|
||||
resources :mass_builds, only: [:create, :new, :index] do
|
||||
|
|
Loading…
Reference in New Issue