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

first commit

parents
public/plans/*.jpg
source "https://rubygems.org"
gem "sinatra"
gem "sinatra-activerecord"
gem 'pg'
gem 'haml'
gem 'barista'
gem 'bcrypt'
gem 'rake'
gem 'chartkick'
gem 'groupdate'
gem 'therubyracer'
gem 'libv8'
GEM
remote: https://rubygems.org/
specs:
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
barista (1.3.0)
coffee-script (~> 2.2)
bcrypt (3.1.7)
builder (3.2.2)
chartkick (1.3.2)
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.9.0)
execjs (2.2.2)
groupdate (2.4.0)
activesupport (>= 3)
haml (4.0.6)
tilt
i18n (0.7.0)
json (1.8.2)
libv8 (3.16.14.7)
minitest (5.5.1)
pg (0.18.1)
rack (1.5.2)
rack-protection (1.5.3)
rack
rake (10.3.2)
ref (1.0.5)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
sinatra-activerecord (2.0.2)
activerecord (>= 3.2)
sinatra (~> 1.0)
therubyracer (0.12.1)
libv8 (~> 3.16.14.0)
ref
thread_safe (0.3.4)
tilt (1.4.1)
tzinfo (1.2.2)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
barista
bcrypt
chartkick
groupdate
haml
libv8
pg
rake
sinatra
sinatra-activerecord
therubyracer
POSAO
====
Logiciel de suivi des travaux sur plusieurs sites, par plusieurs techniciens.
Licence
===
GPLv3 ou supérieur
# Rakefile
require "sinatra/activerecord/rake"
namespace :db do
task :load_config do
require "./posao"
end
end
require './ergasia'
run Sinatra::Application
adapter: postgresql
host: 127.0.0.1
database: ergasia
port: '5432'
username: postgres
password:
menu:
- titre: "Liste des travaux"
icon: "/g3494.png"
url: "/travaux"
- titre: "Plans"
icon: "/plan.png"
url: "/plan"
- titre: "Nouveau travail"
icon: "/g36352.png"
url: "/travaux/0"
- titre: "Statistiques"
icon: "/image3427.png"
url: "/statistique"
- titre: "Configuration"
icon: "/g3282.png"
url: "/configuration"
class CreateStates < ActiveRecord::Migration
def up
create_table :states do |t|
t.string :name, null: false
t.timestamps null: false
end
states = YAML.load_file('./db/migrate/example.yml')["states"]
states.each do |id, state|
State.create name: state
end
end
def down
drop_table :states
end
end
class CreateTypes < ActiveRecord::Migration
def up
create_table :types do |t|
t.string :description, null: false
t.string :icone, null: false
t.string :icone_plan, null: false
t.timestamps null: false
end
types = YAML.load_file('./db/migrate/example.yml')["types"]
types.each do |id, type|
Type.create description: type["description"], icone: type["icone"], icone_plan: type["icone_plan"]
end
end
def down
drop_table :types
end
end
class CreateSites < ActiveRecord::Migration
def up
create_table :sites do |t|
t.string :name, null: false
t.string :plan
end
Site.create name: "Maison", plan:"plan1.png"
Site.create name: "Bungalow", plan:"plan2.png"
end
def down
drop_table :sites
end
end
class CreatePlaces < ActiveRecord::Migration
def up
create_table :places do |t|
t.string :name, null: false
t.string :description
t.belongs_to :site, index: true
t.integer :x
t.integer :y
t.timestamps null: false
end
places = YAML.load_file('./db/migrate/example.yml')["places"]
places.each do |id, place|
site = Site.find(place["site"])
Place.create name: place["description"], site: site, x: place["x"], y: place["y"]
end
end
def down
drop_table :places
end
end
class CreateTechnicians < ActiveRecord::Migration
def up
create_table :technicians do |t|
t.string :name, null: false
t.string :login, null: false
t.string :salt
t.string :passwordhash
t.string :email
t.boolean :admin, default: false
t.boolean :rapporteur, default: false
t.boolean :actif, default: true
t.timestamps null: false
end
create_table :technicians_types do |t|
t.integer :technician_id
t.integer :type_id
t.timestamps null: false
end
create_table :technicians_sites do |t|
t.integer :technician_id
t.integer :site_id
t.timestamps null: false
end
salt = BCrypt::Engine.generate_salt
passwordhash = BCrypt::Engine.hash_secret("admin", salt)
tech = Technician.create name: "Administrateur", login: "admin", salt: salt, passwordhash: passwordhash, admin: true, rapporteur: true
Type.all.each do |type|
Technicians_type.create technician_id: tech.id, type_id: type.id
end
Site.all.each do |site|
Technicians_site.create technician_id: tech.id, site_id: site.id
end
salt = BCrypt::Engine.generate_salt
passwordhash = BCrypt::Engine.hash_secret("test", salt)
tech = Technician.create name: "Tech1", login: "tech1", salt: salt, passwordhash: passwordhash
[1,2,4,5].each do |type|
Technicians_type.create technician_id: tech.id, type_id: type
end
Site.all.each do |site|
Technicians_site.create technician_id: tech.id, site_id: site.id
end
end
def down
drop_table :technicians
drop_table :technicians_types
drop_table :technicians_sites
end
end
class CreateTasks < ActiveRecord::Migration
def up
create_table :tasks do |t|
t.text :description, null: false
t.text :recommendation
t.belongs_to :place, index: true
t.belongs_to :type, index: true
t.belongs_to :state, index: true
t.belongs_to :technician, index: true
t.boolean :new, default: false
t.date :date, null: false
t.date :date_echeance
t.timestamps null: false
end
tasks = YAML.load_file('./db/migrate/example.yml')["tasks"]
tasks.each do |id, task|
tech = (task["tech"] ? Technician.find(task["tech"]) : nil)
Task.create description: task["description"], place: Place.find(task["lieu"]), type: Type.find(task["type"]), technician: tech, state: State.find(task["status"]), date: Date.parse(task["date"]), date_echeance: (task["date_echeance"] ? Date.parse(task["date_echeance"]) : nil)
end
end
def down
drop_table :tasks
end
end
class CreateActions < ActiveRecord::Migration
def up
create_table :actions do |t|
t.string :description, null: false
t.belongs_to :task, index: true
t.belongs_to :technician, index: true
t.belongs_to :supplier, index: true
t.date :date, null: false
t.timestamps null: false
end
end
def down
drop_table :actions
end
end
class CreateSuppliers < ActiveRecord::Migration
def up
create_table :suppliers do |t|
t.string :name, null: false
t.boolean :active, default: true
t.timestamps null: false
end
suppliers = YAML.load_file('./db/migrate/example.yml')["suppliers"]
suppliers.each do |supplier|
Supplier.create name: supplier
end
end
def down
drop_table :suppliers
end
end
class ChangeTasks < ActiveRecord::Migration
def self.up
change_table :tasks do |t|
t.string :technician_validate
end
end
def self.down
change_table :tasks do |t|
t.remove :technician_validate
end
end
end
class ChangePlaces < ActiveRecord::Migration
def up
change_column :places, :x, :float
change_column :places, :y, :float
end
end
class ChangePlaces2 < ActiveRecord::Migration
def change
add_column :places, :num, :string
end
end
tasks:
1:
description: "Panne d'intérupteur au niveau du panneau de commande"
lieu: 4
type: 4
tech: 1
date: "15/12/2014"
status: 1
2:
description: "Fuite du lavabo"
lieu: 6
type: 5
tech: 2
date: "25/01/2015"
status: 1
3:
description: "Néon à changer"
lieu: 1
type: 2
tech: 2
date: "17/01/2015"
status: 1
4:
description: "Problème d'écran"
lieu: 2
type: 3
tech: 1
date: "01/02/2015"
date_echeance: "03/02/2015"
status: 1
5:
description: "Les 3 prises murales ne fonctionnent plus"
lieu: 5
type: 4
tech: 2
date: "02/02/2015"
status: 2
6:
description: "La porte du meuble de rangement ne ferme plus"
lieu: 3
type: 1
tech: 2
date: "04/02/2015"
status: 1
date_echeance: "02/02/2015"
7:
description: "Plus de tonnalité"
lieu: 7
type: 6
tech: 1
date: "04/02/2015"
status: 1
date_echeance: "27/02/2015"
8:
description: "L'ampoule clignotte"
lieu: 5
type: 2
tech: 1
date: "01/02/2015"
status: 1
9:
description: "L'ampoule a grillée"
lieu: 7
type: 2
tech: 1
date: "25/01/2015"
status: 3
10:
description: "Le néon a grillé"
lieu: 11
type: 2
tech: 1
date: "14/01/2015"
status: 4
10:
description: "Ampoule trop faible"
lieu: 12
type: 2
tech: 1
date: "19/01/2015"
status: 1
11:
description: "La prise de droite n'a pas de courant"
lieu: 14
type: 4
tech: 2
date: "02/02/2015"
status: 4
places:
1:
description: "Salon"
x: 800
y: 230
site: 1
2:
description: "Bureau 1"
x: 900
y: 680
site: 1
3:
description: "Chambre 1"
x: 320
y: 110
site: 1
4:
description: "Salle de réunion"
x: 150
y: 220
site: 1
5:
description: "Chambre 4"
x: 900
y: 470
site: 1
6:
description: "Salle de bain 1"
x: 640
y: 425
site: 1
7:
description: "Chambre 2"
x: 320
y: 310
site: 1
8:
description: "Chambre 3"
x: 490
y: 160
site: 1
9:
description: "Bureau 2"
x: 670
y: 680
site: 1
10:
description: "Cuisine"
x: 720
y: 80
site: 1
11:
description: "Buanderie"
x: 170
y: 80
site: 1
12:
description: "Chambre"
x: 760
y: 120
site: 2
13:
description: "Cuisine"
x: 760
y: 425
site: 2
14:
description: "Séjour"
x: 170
y: 240
site: 2
types:
1:
description: "Réparation"
icone: "hammer.png"
icone_plan: "hammer_warning.png"
2:
description: "Eclairage"
icone: "ampoule.png"
icone_plan: "ampoule_warning.png"
3:
description: "Informatique"
icone: "ordinateur.png"
icone_plan: "ordinateur_warning.png"
4:
description: "Electricité"
icone: "lightning.png"
icone_plan: "lightning_warning.png"
5:
description: "Plomberie"
icone: "robinet.png"
icone_plan: "robinet_warning.png"
6:
description: "Téléphonie"
icone: "phone.png"
icone_plan: "phone_warning.png"
7:
description: "Electroménager"
icone: "electro.png"
icone_plan: "electro_warning.png"
states:
1: "A faire"
2: "En cours"
3: "En attente"
4: "Résolu"
5: "Annulé"
suppliers:
- DepanElec
- PlombierSARL
- ABCAutomatisme
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150330135120) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "actions", force: :cascade do |t|
t.string "description", null: false
t.integer "task_id"
t.integer "technician_id"
t.integer "supplier_id"
t.date "date", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "actions", ["supplier_id"], name: "index_actions_on_supplier_id", using: :btree
add_index "actions", ["task_id"], name: "index_actions_on_task_id", using: :btree
add_index "actions", ["technician_id"], name: "index_actions_on_technician_id", using: :btree
create_table "places", force: :cascade do |t|
t.string "name", null: false
t.string "description"
t.integer "site_id"
t.float "x"
t.float "y"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "num"
end
add_index "places", ["site_id"], name: "index_places_on_site_id", using: :btree
create_table "sites", force: :cascade do |t|
t.string "name", null: false
t.string "plan"
end
create_table "states", force: :cascade do |t|
t.string "name", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "suppliers", force: :cascade do |t|
t.string "name", null: false
t.boolean "active", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "tasks", force: :cascade do |t|
t.text "description", null: false
t.text "recommendation"
t.integer "place_id"
t.integer "type_id"
t.integer "state_id"
t.integer "technician_id"
t.boolean "new", default: false
t.date "date", null: false
t.date "date_echeance"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "technician_validate"
end
add_index "tasks", ["place_id"], name: "index_tasks_on_place_id", using: :btree
add_index "tasks", ["state_id"], name: "index_tasks_on_state_id", using: :btree
add_index "tasks", ["technician_id"], name: "index_tasks_on_technician_id", using: :btree
add_index "tasks", ["type_id"], name: "index_tasks_on_type_id", using: :btree
create_table "technicians", force: :cascade do |t|
t.string "name", null: false
t.string "login", null: false
t.string "salt"
t.string "passwordhash"
t.string "email"
t.boolean "admin", default: false
t.boolean "rapporteur", default: false
t.boolean "actif", default: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "technicians_sites", force: :cascade do |t|
t.integer "technician_id"
t.integer "site_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "technicians_types", force: :cascade do |t|
t.integer "technician_id"
t.integer "type_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "types", force: :cascade do |t|
t.string "description", null: false
t.string "icone", null: false
t.string "icone_plan", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
# encoding: UTF-8
def username
session[:identity] ? session[:identity][:nom] : 'Bonjour invité'
end
def authentification?
if !session[:identity] then
session[:previous_url] = request.path
session[:error] = 'Vous devez être authentifié pour visiter cette page'
halt haml(:login_form)
end
end
def admin?
if session[:identity]
return session[:identity][:admin]
else
return false
end
end
def connexion? login, password