-- list-projects: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listProjects_url', 'list-projects', 'list-projects');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listProjects_label', 'Projects', 'Projects');
-- list-projects: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id, is_menu_display, is_menu_backend, is_available_for_guest, priority
) VALUES('list-projects', 'list-projects',
    (SELECT id FROM core_feature_translation WHERE code='menu_listProjects_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listProjects_label' LIMIT 1),
    TRUE, FALSE, FALSE, 102
);

INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='list-projects')
);

-- create-project
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_createProject_url', 'create-project', 'create-project', 'creer-projet');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_createProject_label', 'Create Project', 'Create Project', 'Créer Projet');
INSERT INTO core_feature (
    model, code, url_feature_translation_id, label_feature_translation_id, is_menu_display, is_available_for_guest, priority
) VALUES ('create-project', 'create-project',
    (SELECT id FROM core_feature_translation WHERE code='menu_createProject_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_createProject_label' LIMIT 1),
    TRUE, FALSE, 20
);

INSERT INTO useruser_corefeature_rel(user_id, core_feature_id)
VALUES(
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='create-project')
);

-- list-clients: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listClients_url', 'list-clients', 'list-clients');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listClients_label', 'Clients', 'Clients');
-- list-clients: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
                          is_menu_display, is_available_for_guest, priority
) VALUES('list-clients', 'list-clients',
    (SELECT id FROM core_feature_translation WHERE code='menu_listClients_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listClients_label' LIMIT 1),
    FALSE, FALSE, 102
);

INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='list-clients')
);

-- edit-client: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_editClient_url', 'edit-client', 'edit-client');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_editClient_label', 'Edit', 'Edit');
-- edit-client: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
                          is_menu_display, is_available_for_guest, priority
) VALUES('edit-client', 'edit-client',
    (SELECT id FROM core_feature_translation WHERE code='menu_editClient_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_editClient_label' LIMIT 1),
    FALSE, FALSE, 102
);

INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='edit-client')
);


-- list-providers: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listProviders_url', 'list-providers', 'list-providers');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_listProviders_label', 'Providers', 'Providers');
-- list-providers: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
                          is_menu_display, is_available_for_guest, priority
) VALUES('list-providers', 'list-providers',
    (SELECT id FROM core_feature_translation WHERE code='menu_listProviders_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listProviders_label' LIMIT 1),
    FALSE, FALSE, 102
);

INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='list-providers')
);

-- edit-provider: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_editProvider_url', 'edit-provider', 'edit-provider');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_editProvider_label', 'Edit', 'Edit');
-- edit-provider: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
                          is_menu_display, is_available_for_guest, priority
) VALUES('edit-provider', 'edit-provider',
    (SELECT id FROM core_feature_translation WHERE code='menu_editProvider_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_editProvider_label' LIMIT 1),
    FALSE, FALSE, 102
);
INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='edit-provider')
);

-- create-provider: translations for url/label menu
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_createProvider_url', 'create-provider', 'create-provider');
INSERT INTO core_feature_translation (code, source, en_gb) VALUES ('menu_createProvider_label', 'Edit', 'Edit');
-- create-provider: menu
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
                          is_menu_display, is_available_for_guest, priority
) VALUES('create-provider', 'create-provider',
    (SELECT id FROM core_feature_translation WHERE code='menu_createProvider_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_createProvider_label' LIMIT 1),
    FALSE, FALSE, 102
);
INSERT INTO useruser_corefeature_rel(user_id, core_feature_id) VALUES (
  (SELECT id FROM user_user WHERE email='admin@globsi-admin'),
  (SELECT id FROM core_feature WHERE code='create-provider')
);


--reorganise the priority of the menu tags
UPDATE core_feature SET priority=10 WHERE code='home';
UPDATE core_feature SET priority=50 WHERE code='list-projects';
UPDATE core_feature SET priority=100 WHERE code='list-tasks';
UPDATE core_feature SET priority=150 WHERE code='list-clients';
UPDATE core_feature SET priority=200 WHERE code='list-providers';
UPDATE core_feature SET priority=250 WHERE code='list-isp';
UPDATE core_feature SET priority=900 WHERE code='my-profile';
UPDATE core_feature SET priority=1000 WHERE code='login';
UPDATE core_feature SET priority=1000 WHERE code='logout';

UPDATE core_feature_translation SET source='Tasks', en_gb='Tasks' WHERE code='menu_listTasks_label';
UPDATE core_feature SET is_menu_display=TRUE WHERE code IN ('list-projects', 'list-tasks', 'list-clients', 'list-isp', 'list-providers', 'list-users', 'list-translations');
UPDATE core_feature SET is_menu_display=FALSE WHERE code IN ('edit-projects', 'edit-tasks', 'edit-clients', 'edit-isp', 'edit-providers', 'edit-users', 'edit-translations');
UPDATE core_feature SET is_menu_display=FALSE WHERE code IN ('create-projects', 'create-tasks', 'create-clients', 'create-isp', 'create-providers', 'create-users', 'create-translations');












DROP TABLE IF EXISTS globsi_providers_config;
CREATE TABLE globsi_providers_config(
  id SERIAL,
  create_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  k VARCHAR(128) NOT NULL,
  v VARCHAR(128) NOT NULL,
  is_active BOOLEAN NOT NULL DEFAULT TRUE,
  comment TEXT NOT NULL DEFAULT '',
  CONSTRAINT globsiProvidersConfig_id_pk PRIMARY KEY(id),
  CONSTRAINT globsiProvidersConfig_k_uk UNIQUE(k)
);
INSERT INTO globsi_providers_config(k, v)
VALUES('db_server', 'localhost'),
  ('db_name', 'globsi_providers'),
  ('db_user', 'odoo11'),
  ('db_password', 'odoo11');



-- core_feature: list-translations
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listTranslations_url', 'list-translations', 'list-translations', 'lister-traductions');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listTranslations_label', 'List Translations', 'List Translations', 'Lister Traductions');
INSERT INTO core_feature (
    model, code, url_feature_translation_id, label_feature_translation_id, is_menu_display, is_menu_backend, is_available_for_guest, priority
) VALUES ('list-translations', 'list-translations',
    (SELECT id FROM core_feature_translation WHERE code='menu_listTranslations_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listTranslations_label' LIMIT 1),
    TRUE, FALSE, FALSE, 30
);

-- core_feature: edit-translation
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editTranslation_url', 'edit-translation', 'edit-translation', 'editer-traduction');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editTranslation_label', 'Edit Translation', 'Edit Translation', 'Éditer Traduction');
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
    is_menu_display, is_menu_backend, is_available_for_guest
) VALUES ('edit-translation', 'edit-translation',
    (SELECT id FROM core_feature_translation WHERE code='menu_editTranslation_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_editTranslation_label' LIMIT 1),
    FALSE, FALSE, FALSE
);

-- core_feature: list-users
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listUsers_url', 'list-users', 'list-users', 'lister-utilisateurs');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listUsers_label', 'List Users', 'List Users', 'Lister Users');
INSERT INTO core_feature (
    model, code, url_feature_translation_id, label_feature_translation_id,
		is_menu_display, is_menu_backend, is_available_for_guest, priority
) VALUES ('list-users', 'list-users',
    (SELECT id FROM core_feature_translation WHERE code='menu_listUsers_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listUsers_label' LIMIT 1),
    TRUE, FALSE, FALSE, 30
);

-- core_feature: edit-user
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editUser_url', 'edit-user', 'edit-user', 'editer-traduction');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editUser_label', 'Edit User', 'Edit User', 'Éditer User');
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
    is_menu_display, is_menu_backend, is_available_for_guest
) VALUES ('edit-user', 'edit-user',
    (SELECT id FROM core_feature_translation WHERE code='menu_editUser_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_editUser_label' LIMIT 1),
    FALSE, FALSE, FALSE
);

-- core_feature: list-tasks
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listTasks_url', 'list-tasks', 'list-tasks', 'lister-taches');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_listTasks_label', 'List Tasks', 'List Tasks', 'Lister Tâches');
INSERT INTO core_feature (
    model, code, url_feature_translation_id, label_feature_translation_id,
		is_menu_display, is_menu_backend, is_available_for_guest, priority
) VALUES ('list-tasks', 'list-tasks',
    (SELECT id FROM core_feature_translation WHERE code='menu_listTasks_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_listTasks_label' LIMIT 1),
    TRUE, FALSE, FALSE, 30
);

-- core_feature: edit-task
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editTask_url', 'edit-task', 'edit-task', 'editer-tache');
INSERT INTO core_feature_translation (code, source, en_gb, fr_fr) VALUES('menu_editTask_label', 'Edit Task', 'Edit Task', 'Éditer Tâche');
INSERT INTO core_feature (model, code, url_feature_translation_id, label_feature_translation_id,
    is_menu_display, is_menu_backend, is_available_for_guest
) VALUES ('edit-task', 'edit-task',
    (SELECT id FROM core_feature_translation WHERE code='menu_editTask_url' LIMIT 1),
    (SELECT id FROM core_feature_translation WHERE code='menu_editTask_label' LIMIT 1),
    FALSE, FALSE, FALSE
);
