Commit dbd2036b authored by Jean-Noël Rouchon's avatar Jean-Noël Rouchon

Création de la configuration des instances

parent 6b5a9c8c
......@@ -69,6 +69,9 @@ $( window ).load(function() {
} else if (url.search("/logout") >= 0) {
console.log( "** jquery logout **" );
Logout_init();
} else if (url.search("/config_modules") >= 0) {
console.log( "** jquery config **" );
Config_init();
}
$('[data-toggle="tooltip"]').tooltip()
......
function Config_init(){
console.log( "** fonction Config init **" );
$("#instance-table").bootstrapTable({
id: 'instance-table',
toolbar: '#instance-toolbar',
idField: 'name',
search: true, // active la recherche
reorderableColumns: true,
striped: true, // ligne colore une sur 2
showColumns: false, // bouton afficher et cacher des colonnes, inutile car groupement
showRefresh: true, // bouton refresh
showToggle: false, // affichage different des données tableau
showExport: true, // bouton d'export de donnees
showFooter: false
});
}
\ No newline at end of file
......@@ -688,9 +688,8 @@ function SuperAdmin_init() {
str += `
<div id="tab`+element["id"]+`" class="tab-pane fade `+active+`"><br/>
`;
data = element["datas"];
data = element["domain_datas"];
for (var key in data){
console.log(element["value"]);
value = "";
if (element["value"]) {
value = element["value"][key] ? element["value"][key] : "";
......
// Place all the styles related to the Instances controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
......@@ -28,7 +28,7 @@ class ConfigModulesController < ApplicationController
# GET /config_modules/1
# GET /config_modules/1.json
def show
@instances = Instance.where(config_module_id: @module.id)
end
# GET /config_modules/1/edit
......@@ -48,9 +48,9 @@ class ConfigModulesController < ApplicationController
@infos = []
@modules.each do |mod|
domain_infos = DomainInfo.where(domain_id: params[:domain_id], config_module_id: mod.id).first
info = {id: mod.id, name: mod.name, resume: mod.resume, font: mod.font, datas: eval(mod.datas)}
info = {id: mod.id, name: mod.name, resume: mod.resume, font: mod.font, domain_datas: mod.domain_datas ? eval(mod.domain_datas): nil}
if domain_infos
value = eval(domain_infos[:data])
value = domain_infos[:domain_datas] ? eval(domain_infos[:domain_datas]) : nil
@infos << info.merge({value: value})
else
@infos << info.merge({value: nil})
......
class InstancesController < ApplicationController
before_action :set_instance, only: [:show, :edit, :update, :destroy]
# GET /instances
# GET /instances.json
def index
@instances = Instance.all
end
# GET /instances/1
# GET /instances/1.json
def show
end
# GET /instances/new
def new
@instance = Instance.new
end
# GET /instances/1/edit
def edit
end
# POST /instances
# POST /instances.json
def create
@instance = Instance.new(instance_params)
respond_to do |format|
if @instance.save
format.html { redirect_to @instance, notice: 'Instance was successfully created.' }
format.json { render :show, status: :created, location: @instance }
else
format.html { render :new }
format.json { render json: @instance.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /instances/1
# PATCH/PUT /instances/1.json
def update
respond_to do |format|
if @instance.update(instance_params)
format.html { redirect_to @instance, notice: 'Instance was successfully updated.' }
format.json { render :show, status: :ok, location: @instance }
else
format.html { render :edit }
format.json { render json: @instance.errors, status: :unprocessable_entity }
end
end
end
# DELETE /instances/1
# DELETE /instances/1.json
def destroy
@instance.destroy
respond_to do |format|
format.html { redirect_to instances_url, notice: 'Instance was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_instance
@instance = Instance.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def instance_params
params.require(:instance).permit(:config_module_id, :name, :description, :active, :datas)
end
end
module InstancesHelper
end
......@@ -17,4 +17,5 @@
class DomainInfo < ActiveRecord::Base
belongs_to :config_module
belongs_to :instance
end
# Copyright (c) 2019 Jean-Noël Rouchon <jnoel@mithril.re>
#
# This file is part of Zourit.
#
# Zourit is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Zourit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Zourit. If not, see <http://www.gnu.org/licenses/>.
class Instance < ActiveRecord::Base
belongs_to :config_module
has_many :domain_infos
end
......@@ -13,7 +13,7 @@
</div>
<% @modules.each do |m| %>
<div class="col-sm-6 col-md-3 col-lg-1">
<a href="/config_modules/<%= m.id %>/edit">
<a href="/config_modules/<%= m.id %>">
<div class="caption tuile_mini">
<span><i class="fa fa-gear fa-2x"></i></span>
<p><%= m.name %></p>
......
json.array!(@modules) do |mod|
json.extract! mod, :id, :name, :resume, :font
json.datas eval(mod.datas)
json.datas eval(mod.domain_datas)
end
\ No newline at end of file
json.array!(@infos) do |info|
json.extract! info, :id, :name, :resume, :font, :datas, :value
json.extract! info, :id, :name, :resume, :font, :domain_datas, :value
end
\ No newline at end of file
<div class="z-user-page">
<div id="Groups-table-container" class="container">
<div class="z-index-page">
<div class="container">
<div class="panel panel-warning shadow">
<div class="panel-heading clearfix"><h1><a href="/configs" title="<%= I18n.t "terms.backmain"%>"><i class="fa fa-arrow-left" aria-hidden="true"></i></a>Configuration de <%= @module.name %></h1></div>
<div class="panel-heading clearfix">
<h1>
<%= "Gestion des instances de #{@module.name}" %>
</h1>
</div>
<div class="panel-body">
<div class="col-md-6">
<i class="fa <%= @module.icon %> fa-4x"></i>
<p><%= @module.resume %></p>
</div>
<div class="col-md-6 well well-sm">
<%= form_for(@module) do |f| %>
<div class="field">
<%= f.label 'Nom du salon' %><br>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-globe" aria-hidden="true"></i></span>
<%= f.text_field :url, class: "form-control", placeholder: I18n.t "terms.version" + "#{@module.name}"%>
</div>
</div>
<div id="instance-toolbar" >
<%= link_to new_instance_path do %>
<button type="button" class="btn btn-primary">
<i></i> Nouvelle instance
</button>
<% end %>
</div>
<table id="instance-table" data-classes="table table-no-bordered" data-detail-view="true">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Active</th>
<th>Datas</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% @instances.each do |instance| %>
<tr>
<td><%= instance.name %></td>
<td><%= instance.description %></td>
<td><%= instance.active %></td>
<td><%= instance.datas %></td>
<td><%= link_to 'Show', instance %></td>
<td><%= link_to 'Edit', edit_instance_path(instance) %></td>
<td><%= link_to 'Destroy', instance, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
<%= form_for(@instance) do |f| %>
<% if @instance.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@instance.errors.count, "error") %> prohibited this instance from being saved:</h2>
<ul>
<% @instance.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :config_module_id %><br>
<%= f.text_field :config_module_id %>
</div>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :active %><br>
<%= f.check_box :active %>
</div>
<div class="field">
<%= f.label :datas %><br>
<%= f.text_field :datas %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
json.extract! instance, :id, :config_module_id, :name, :description, :active, :datas, :created_at, :updated_at
json.url instance_url(instance, format: :json)
<h1>Editing Instance</h1>
<%= render 'form' %>
<%= link_to 'Show', @instance %> |
<%= link_to 'Back', instances_path %>
<p id="notice"><%= notice %></p>
<h1>Listing Instances</h1>
<table>
<thead>
<tr>
<th>Config module</th>
<th>Name</th>
<th>Description</th>
<th>Active</th>
<th>Datas</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @instances.each do |instance| %>
<tr>
<td><%= instance.config_module %></td>
<td><%= instance.name %></td>
<td><%= instance.description %></td>
<td><%= instance.active %></td>
<td><%= instance.datas %></td>
<td><%= link_to 'Show', instance %></td>
<td><%= link_to 'Edit', edit_instance_path(instance) %></td>
<td><%= link_to 'Destroy', instance, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%= link_to 'New Instance', new_instance_path %>
json.array! @instances, partial: 'instances/instance', as: :instance
<h1>New Instance</h1>
<%= render 'form' %>
<%= link_to 'Back', instances_path %>
<p id="notice"><%= notice %></p>
<p>
<strong>Config module:</strong>
<%= @instance.config_module %>
</p>
<p>
<strong>Name:</strong>
<%= @instance.name %>
</p>
<p>
<strong>Description:</strong>
<%= @instance.description %>
</p>
<p>
<strong>Active:</strong>
<%= @instance.active %>
</p>
<p>
<strong>Datas:</strong>
<%= @instance.datas %>
</p>
<%= link_to 'Edit', edit_instance_path(@instance) %> |
<%= link_to 'Back', instances_path %>
json.partial! "instances/instance", instance: @instance
Rails.application.routes.draw do
resources :instances
resources :pads_users
resources :pads_groups
resources :pads
......
class CreateInstances < ActiveRecord::Migration
def change
create_table :instances do |t|
t.references :config_module, index: true, foreign_key: true
t.string :name
t.text :description
t.boolean :active, default: true
t.string :datas
t.timestamps null: false
end
end
end
class AddInstanceDatasToConfigModule < ActiveRecord::Migration
def change
add_column :config_modules, :instance_datas, :string
rename_column :config_modules, :datas, :domain_datas
end
end
class AddActiveToDomainInfo < ActiveRecord::Migration
def change
add_column :domain_infos, :active, :boolean, default: true
end
end
class AddInstanceToDomainInfo < ActiveRecord::Migration
def change
add_reference :domain_infos, :instance, index: true, foreign_key: true
end
end
......@@ -11,31 +11,47 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190516181743) do
ActiveRecord::Schema.define(version: 20190527102401) do
create_table "config_modules", force: :cascade do |t|
t.string "name"
t.string "title"
t.string "icon"
t.text "resume"
t.boolean "active", default: false
t.boolean "active", default: false
t.string "url"
t.string "url_local"
t.boolean "new_page", default: false
t.boolean "beta", default: false
t.boolean "new_page", default: false
t.boolean "beta", default: false
t.string "font"
t.integer "order", default: 0
t.string "datas"
t.integer "order", default: 0
t.string "domain_datas"
t.boolean "core"
t.string "instance_datas"
end
create_table "domain_infos", force: :cascade do |t|
t.string "domain_id"
t.integer "config_module_id"
t.string "data"
t.boolean "active", default: true
t.integer "instance_id"
end
add_index "domain_infos", ["config_module_id"], name: "index_domain_infos_on_config_module_id"
add_index "domain_infos", ["instance_id"], name: "index_domain_infos_on_instance_id"
create_table "instances", force: :cascade do |t|
t.integer "config_module_id"
t.string "name"
t.text "description"
t.boolean "active", default: true
t.string "datas"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "instances", ["config_module_id"], name: "index_instances_on_config_module_id"
create_table "pads", force: :cascade do |t|
t.string "name"
......
......@@ -12,7 +12,8 @@ namespace :modules do
config = YAML.load_file(file)
configModule = ConfigModule.where(name: config["program"]).first
if configModule
configModule.datas = config["datas"]
configModule.domain_datas = config["domain_datas"]
configModule.instance_datas = config["instance_datas"]
configModule.core = (dir.include? "core")
configModule.save
puts "-> Module #{configModule.name} updated"
......@@ -21,7 +22,8 @@ namespace :modules do
title: config["title"],
resume: config["resume"],
font: config["font"],
datas: config["datas"],
domain_datas: config["domain_datas"],
instance_datas: config["instance_datas"],
core: (dir.include? "core")
puts "-> Module #{config["program"]} created"
end
......
......@@ -2,6 +2,4 @@ name: "garradin"
program: "Garradin"
title: "Ma compta"
resume: "Avec ce module, j'accède à la comptabilité de mon association"
font: "fa-area-chart"
datas:
url: "https://bac-a-sable.compta.bertel.re"
\ No newline at end of file
font: "fa-area-chart"
\ No newline at end of file
......@@ -2,6 +2,4 @@ name: "nextcloud"
program: "Owncloud"
title: "Mes fichiers"
resume: "Grâce au service NextCloud je peux stocker des fichiers, les retrouver et les partager avec mes collègues"
font: "fa-cloud"
datas:
url: "URL du serveur"
\ No newline at end of file
font: "fa-cloud"
\ No newline at end of file
......@@ -3,9 +3,15 @@ program: "Zimbra"
title: "Mes emails"
resume: "Je consulte mes mails, mes agendas partagés, mes contacts, mes tâches dans ma messagerie Zimbra"
font: "fa-envelope"
datas:
url: "URL du serveur"
authkey: "Clé d'authentification"
instance_datas:
ssh_host: "Hôte SSH"
ssh_user: "Utilisateur SSH"
ssh_password: "Mot de passe SSH"
\ No newline at end of file
ssh_password: "Mot de passe SSH"
domain_datas:
authkey: "Clé d'authentification"
user_datas:
quota: "Quota réservé"
email_b: "Module Email"
calendar_b: "Module Calendrier"
contact_b: "Module Contact"
task_b: "Module Tâches"
\ No newline at end of file
require 'test_helper'
class InstancesControllerTest < ActionController::TestCase
setup do
@instance = instances(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:instances)
end
test "should get new" do
get :new
assert_response :success
end
test "should create instance" do
assert_difference('Instance.count') do
post :create, instance: { active: @instance.active, config_module_id: @instance.config_module_id, datas: @instance.datas, description: @instance.description, name: @instance.name }
end
assert_redirected_to instance_path(assigns(:instance))
end
test "should show instance" do
get :show, id: @instance
assert_response :success
end
test "should get edit" do
get :edit, id: @instance
assert_response :success
end
test "should update instance" do
patch :update, id: @instance, instance: { active: @instance.active, config_module_id: @instance.config_module_id, datas: @instance.datas, description: @instance.description, name: @instance.name }
assert_redirected_to instance_path(assigns(:instance))
end
test "should destroy instance" do
assert_difference('Instance.count', -1) do
delete :destroy, id: @instance
end
assert_redirected_to instances_path
end
end
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
config_module_id:
name: MyString
description: MyText
active: false
datas: MyString
two:
config_module_id:
name: MyString
description: MyText
active: false
datas: MyString
require 'test_helper'
class InstanceTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment