Skip to content

Commit

Permalink
Content Views: Initial work to generate a content view prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehelms committed Feb 6, 2014
1 parent a5be5ff commit 04ba8a6
Show file tree
Hide file tree
Showing 52 changed files with 3,458 additions and 89 deletions.
3 changes: 1 addition & 2 deletions app/assets/stylesheets/katello/widgets/path_selector.scss
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ $widget-background-color: #F9F8F8;
display: block;
font-weight: normal;
font-size: 10px;
margin-bottom: 0;
height: 37px;
margin: 0;

.checkbox_holder {
float: left;
Expand Down
36 changes: 36 additions & 0 deletions app/controllers/katello/content_views_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Katello
class ContentViewsController < Katello::ApplicationController

before_filter :authorize

def rules
index_rule = lambda { true }

{
:index => index_rule,
:all => index_rule
}
end

def index
render 'bastion/layouts/application', :layout => false
end

def all
redirect_to :action => 'index', :anchor => '/content_views'
end

end
end
28 changes: 28 additions & 0 deletions app/lib/katello/navigation/items/content_views.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Katello
module Navigation
module Items
class ContentViews < Navigation::Item

def initialize(organization)
@key = :content_views
@display = _("Content Views (new)")
@authorization = lambda{ ContentView.any_readable?(organization) }
@url = content_views_path + '#/content_views'
end

end
end
end
end
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
end
end

resources :content_views, :only => [:index] do
collection do
get :all
end
end

resources :activation_keys do
collection do
get :auto_complete_search
Expand Down
2 changes: 2 additions & 0 deletions engines/bastion/app/assets/javascripts/bastion/bastion.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
//= require "bastion/angular-gettext/angular-gettext"
//= require "bastion/angular-blocks/angular-blocks"
//= require_tree "../../../../vendor/assets/javascripts/bastion/angular-bootstrap"
//= require "bastion/angular-animate/angular-animate"
//= require "bastion/alchemy/alchemy"

//= require "katello/common/katello.global"
Expand Down Expand Up @@ -59,6 +60,7 @@

//= require "bastion/content-views/content-views.module"
//= require_tree "./content-views"
//= stub "bastion/content-views/content-view.factory"

//= require "bastion/errata/errata.module"
//= require_tree "./errata"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ angular.module('Bastion', [
'ngSanitize',
'ui.bootstrap',
'ui.bootstrap.tpls',
'ngAnimate',
'angular-blocks',
'Bastion.i18n',
'Bastion.menu',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
/**
* Copyright 2013 Red Hat, Inc.
*
* This software is licensed to you under the GNU General Public
* License as published by the Free Software Foundation; either version
* 2 of the License (GPLv2) or (at your option) any later version.
* There is NO WARRANTY for this software, express or implied,
* including the implied warranties of MERCHANTABILITY,
* NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
* have received a copy of GPLv2 along with this software; if not, see
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
**/

/**
* @ngdoc service
* @name Bastion.content-views.factory:ContentView
*
* @description
* Provides a $Resource for interacting with environments.
*/
angular.module('Bastion.content-views').factory('ContentView',
[function($resource, Routes, CurrentOrganization) {

var Resource = function(id, create) {
var name = id ? 'Content View ' + id : '',
label = id ? 'content_view_' + id : '',
generatedVersions = [],
counts = {
products: 0,
repositories: 0,
puppet_modules: 0
};

this.id = id;

if (id !== undefined && !create) {
versions.call(this, function(response) {
generatedVersions = response.results;
});

counts = {
products: id + id,
repositories: id * id,
puppet_modules: id * id - id
};
}

return {
id: id,
name: name,
label: label,
created: new Date(),
environments: [
'Library',
'Dev'
],
counts: counts,
user: 'mister manager',
permissions: {
editable: true
},
organization: {
id: 1,
name: 'ACME_Corporation'
},
$save: save,
$versions: versions,
$version: version,
versions: generatedVersions,
repositories: [],
filters: [],
$publish: publish,
$puppetModules: puppetModules,
$filters: filters,
$addFilter: addFilter
};
};

var Version = function(id) {
return {
id: id,
name: 'Version ' + id,
label: 'version_' + id,
promoted: new Date(),
environments: [
{
id: 1,
name: 'Library'
},{
id: 2,
name: 'Dev'
}
],
counts: {
products: id + id,
repositories: id * id,
packages: id^id,
puppet_modules: id * id - id,
errata: {
bugs: id,
security: id + id,
enhancements: id
}
},
user: 'mister manager'
};
};

var Filter = function(id) {
return {
id: id,
name: 'Version ' + id,
created: new Date(),
description: '',
contentType: '',
counts: {
products: 0,
repositories: 0,
packages: 0,
puppet_modules: id * id - id,
errata: {
bugs: 0,
security: 0,
enhancements: 0
}
}
};
};

var save = function(successCallback, errorCallback) {
var view = new Resource(results.length + 1, true);

view.name = this.name;

results.push(view);
successCallback(view);
};

var versions = function(callback) {
var versions = generateVersions(this.id);

if (this.id < 10) {
this.versions = versions;
}

callback({
offset: 0,
total: versions.length,
subtotal: versions.length,
limit: 25,
search: "",
sort: {by: "name", order: "ASC"},
results: this.versions
});
};

var version = function(params, callback) {
var found;

angular.forEach(this.versions, function(version) {
if (params.toString() === version.id.toString()) {
found = version;
}
});

callback(found);
};

var publish = function(params, callback) {
var version = new Version(this.versions.length + 1);

version.name = params.name;

this.versions.push(version);
callback(version);
};

var puppetModules = function(callback) {
var modules = generatePuppetModules(this.id);

if (this.modules.length === 0) {
this.modules = modules;
}

callback({
offset: 0,
total: modules.length,
subtotal: modules.length,
limit: 25,
search: "",
sort: {by: "name", order: "ASC"},
results: this.modules
});
};

var filters = function(callback) {
var filters = this.filters;

callback({
offset: 0,
total: filters.length,
subtotal: filters.length,
limit: 25,
search: "",
sort: {by: "name", order: "ASC"},
results: filters
});
};

var addFilter = function(params, callback) {
var filter = new Filter(this.filters.length + 1);

filter.name = params.name;
filter.description = params.description;
filter.contentType = params.contentType;

this.filters.push(filter);
callback(filter);
};

var results = generateViews(10, save, versions, publish, puppetModules);

Resource.query = function(params, callback) {
callback({
offset: 0,
total: 10,
subtotal: 10,
limit: 25,
search: "",
sort: {by: "name", order: "ASC"},
results: results
});
};

Resource.get = function(params, callback) {
var view;

angular.forEach(results, function(result) {
if (params.id.toString() === result.id.toString()) {
view = result;
}
});

callback(view);

return view;
};

function generateViews(numViews, save, versions, publish, puppetModules) {
var views = [],
i;

for(i = 1; i <= numViews; i += 1) {
views.push(new Resource(i));
}

return views;
}

function generateVersions(numVersions) {
var versions = [],
i;

for(i = 1; i <= numVersions; i += 1) {
versions.push(new Version(i));
}

return versions;
}

return Resource;

}]
);
Loading

0 comments on commit 04ba8a6

Please sign in to comment.