summaryrefslogtreecommitdiff
path: root/addons/google_drive/static
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/google_drive/static
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/google_drive/static')
-rw-r--r--addons/google_drive/static/description/icon.pngbin0 -> 10435 bytes
-rw-r--r--addons/google_drive/static/description/icon.svg22
-rw-r--r--addons/google_drive/static/src/css/google_drive.css5
-rw-r--r--addons/google_drive/static/src/img/drive_icon.pngbin0 -> 1542 bytes
-rw-r--r--addons/google_drive/static/src/img/drive_icon_mono.pngbin0 -> 479 bytes
-rw-r--r--addons/google_drive/static/src/js/gdrive.js93
-rw-r--r--addons/google_drive/static/src/xml/gdrive.xml14
-rw-r--r--addons/google_drive/static/tests/gdrive_test.js154
-rw-r--r--addons/google_drive/static/tests/mock_server.js22
9 files changed, 310 insertions, 0 deletions
diff --git a/addons/google_drive/static/description/icon.png b/addons/google_drive/static/description/icon.png
new file mode 100644
index 00000000..3d828754
--- /dev/null
+++ b/addons/google_drive/static/description/icon.png
Binary files differ
diff --git a/addons/google_drive/static/description/icon.svg b/addons/google_drive/static/description/icon.svg
new file mode 100644
index 00000000..d0f8c5aa
--- /dev/null
+++ b/addons/google_drive/static/description/icon.svg
@@ -0,0 +1,22 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="70" height="70" viewBox="0 0 70 70">
+ <defs>
+ <path id="icon-a" d="M4,5.35309892e-14 C36.4160122,9.87060235e-15 58.0836068,-3.97961823e-14 65,5.07020818e-14 C69,6.733808e-14 70,1 70,5 C70,43.0488877 70,62.4235458 70,65 C70,69 69,70 65,70 C61,70 9,70 4,70 C1,70 7.10542736e-15,69 7.10542736e-15,65 C7.25721566e-15,62.4676575 3.83358709e-14,41.8005206 3.60818146e-14,5 C-1.13686838e-13,1 1,5.75716207e-14 4,5.35309892e-14 Z"/>
+ <linearGradient id="icon-c" x1="100%" x2="0%" y1="0%" y2="100%">
+ <stop offset="0%" stop-color="#CDC484"/>
+ <stop offset="100%" stop-color="#B5AA59"/>
+ </linearGradient>
+ </defs>
+ <g fill="none" fill-rule="evenodd">
+ <mask id="icon-b" fill="#fff">
+ <use xlink:href="#icon-a"/>
+ </mask>
+ <g mask="url(#icon-b)">
+ <rect width="70" height="70" fill="url(#icon-c)"/>
+ <path fill="#FFF" fill-opacity=".383" d="M4,1.8 L65,1.8 C67.6666667,1.8 69.3333333,1.13333333 70,-0.2 C70,2.46666667 70,3.46666667 70,2.8 L1.10547097e-14,2.8 C-1.65952376e-14,3.46666667 -2.9161925e-14,2.46666667 -2.66453526e-14,-0.2 C0.666666667,1.13333333 2,1.8 4,1.8 Z" transform="matrix(1 0 0 -1 0 2.8)"/>
+ <path fill="#393939" d="M4,57 C2,57 -7.10542736e-15,56.8519481 0,52.8545455 L2.12440903e-16,27.3064832 L28,0 L43,0 L56,22.8 L56,30.0545455 L59,30.0545455 L59,40.4181818 L44.6699749,57 L4,57 Z" opacity=".324" transform="translate(0 13)"/>
+ <path fill="#000" fill-opacity=".383" d="M4,4 L65,4 C67.6666667,4 69.3333333,3 70,1 C70,3.66666667 70,5 70,5 L1.77635684e-15,5 C1.77635684e-15,5 1.77635684e-15,3.66666667 1.77635684e-15,1 C0.666666667,3 2,4 4,4 Z" transform="translate(0 65)"/>
+ <path fill="#000" fill-rule="nonzero" d="M56.7194481,37 L54.763358,37 C51.587786,37 49.6666667,37 49,37 C48.3333333,37 48,37.3333333 48,38 C48,38 48,38.3333333 48,39 C48,39.4151965 47.4828357,39.6580048 46.8063818,39.8 L42.8848883,39.8 L28,15 L43.5151117,15 L56.7194481,37 Z M42.7777778,55 L21.6,55 L29.1857817,42.2 L42.4222732,42.2 C42.000051,43.1554536 41.5259599,44.4221203 41,46 C41.6666667,46.6666667 42,47.3333333 42,48 C42,48.6666667 42,49 42,49 C41.3333333,49.6666667 41,50.3333333 41,51 C41,51.4444444 41.5925926,52.7777778 42.7777778,55 Z M34.4,29.0223518 L19.7395382,54.2 L12,40.9776482 L26.6604618,15.8 L34.4,29.0223518 Z M59.1120093,49.6163985 L60.7668484,50.585058 C60.9558409,50.6956709 61.043561,50.9244177 60.9788291,51.1357594 C60.5489654,52.5392703 59.8150519,53.807242 58.8551784,54.8603674 C58.7072273,55.022782 58.4680825,55.059636 58.279231,54.9491254 L56.6256345,53.9806234 C55.9298948,54.5851374 55.1300224,55.0541223 54.2662772,55.3639727 L54.2662772,57.3006617 C54.2662804,57.5219079 54.1150225,57.7135885 53.9021551,57.7620931 C52.5447646,58.0712105 51.0869171,58.0871979 49.661028,57.7623688 C49.4478436,57.7138157 49.2958963,57.5223205 49.2958963,57.3007404 L49.2958963,55.3639727 C48.4321428,55.0541404 47.6322673,54.5851537 46.936539,53.9806234 L45.2829425,54.9491254 C45.0940909,55.059636 44.8549462,55.022782 44.7069951,54.8603674 C43.7471604,53.807242 43.0132081,52.5392703 42.5833444,51.1357594 C42.5186125,50.9244571 42.6063326,50.6957102 42.795325,50.585058 L44.450203,49.6163985 C44.2839859,48.7026748 44.2839859,47.7658257 44.450203,46.852102 L42.7953639,45.8834424 C42.6063714,45.7728296 42.5186513,45.5440828 42.5833832,45.332741 C43.0132469,43.9292302 43.7471604,42.6612585 44.7070339,41.6081331 C44.8549851,41.4457185 45.0941298,41.4088644 45.2829813,41.5193751 L46.9365778,42.4878771 C47.6323176,41.8833631 48.4321899,41.4143782 49.2959351,41.1045278 L49.2959351,39.1677994 C49.2959319,38.9465532 49.4471898,38.7548726 49.6600572,38.706368 C51.0174478,38.3972506 52.4752952,38.3812631 53.9011843,38.7060923 C54.1143687,38.7546454 54.266316,38.9461406 54.266316,39.1677207 L54.266316,41.1044884 C55.1300695,41.4143207 55.929945,41.8833074 56.6256733,42.4878377 L58.2792698,41.5193357 C58.4681214,41.4088251 58.7072661,41.4456791 58.8552172,41.6080937 C59.8150519,42.6612191 60.5490043,43.9291908 60.9788679,45.3327017 C61.0435999,45.544004 60.9558797,45.7727509 60.7668873,45.8834031 L59.1120093,46.8520626 C59.2782268,47.7657995 59.2782268,48.7026616 59.1120093,49.6163985 Z M54.8876185,48.2342305 C54.8876185,46.497188 53.4940371,45.0839902 51.7811062,45.0839902 C50.0681752,45.0839902 48.6745938,46.497188 48.6745938,48.2342305 C48.6745938,49.9712731 50.0681752,51.3844709 51.7811062,51.3844709 C53.4940371,51.3844709 54.8876185,49.9712731 54.8876185,48.2342305 Z M13.808,58.508 L12.524,58.508 L12.524,57.716 L16.034,57.716 L16.034,58.508 L14.75,58.508 L14.75,62 L13.808,62 L13.808,58.508 Z M16.526,57.716 L17.852,57.716 L18.854,60.662 L18.866,60.662 L19.814,57.716 L21.14,57.716 L21.14,62 L20.258,62 L20.258,58.964 L20.246,58.964 L19.196,62 L18.47,62 L17.42,58.994 L17.408,58.994 L17.408,62 L16.526,62 L16.526,57.716 Z" opacity=".3"/>
+ <path fill="#FFF" fill-rule="nonzero" d="M56.7194481,35 L54.763358,35 C51.587786,35 49.6666667,35 49,35 C48.3333333,35 48,35.3333333 48,36 C48,36 48,36.3333333 48,37 C48,37.4151965 47.4828357,37.6580048 46.8063818,37.8 L42.8848883,37.8 L28,13 L43.5151117,13 L56.7194481,35 Z M42.7777778,53 L21.6,53 L29.1857817,40.2 L42.4222732,40.2 C42.000051,41.1554536 41.5259599,42.4221203 41,44 C41.6666667,44.6666667 42,45.3333333 42,46 C42,46.6666667 42,47 42,47 C41.3333333,47.6666667 41,48.3333333 41,49 C41,49.4444444 41.5925926,50.7777778 42.7777778,53 Z M34.4,27.0223518 L19.7395382,52.2 L12,38.9776482 L26.6604618,13.8 L34.4,27.0223518 Z M59.1120093,47.6163985 L60.7668484,48.585058 C60.9558409,48.6956709 61.043561,48.9244177 60.9788291,49.1357594 C60.5489654,50.5392703 59.8150519,51.807242 58.8551784,52.8603674 C58.7072273,53.022782 58.4680825,53.059636 58.279231,52.9491254 L56.6256345,51.9806234 C55.9298948,52.5851374 55.1300224,53.0541223 54.2662772,53.3639727 L54.2662772,55.3006617 C54.2662804,55.5219079 54.1150225,55.7135885 53.9021551,55.7620931 C52.5447646,56.0712105 51.0869171,56.0871979 49.661028,55.7623688 C49.4478436,55.7138157 49.2958963,55.5223205 49.2958963,55.3007404 L49.2958963,53.3639727 C48.4321428,53.0541404 47.6322673,52.5851537 46.936539,51.9806234 L45.2829425,52.9491254 C45.0940909,53.059636 44.8549462,53.022782 44.7069951,52.8603674 C43.7471604,51.807242 43.0132081,50.5392703 42.5833444,49.1357594 C42.5186125,48.9244571 42.6063326,48.6957102 42.795325,48.585058 L44.450203,47.6163985 C44.2839859,46.7026748 44.2839859,45.7658257 44.450203,44.852102 L42.7953639,43.8834424 C42.6063714,43.7728296 42.5186513,43.5440828 42.5833832,43.332741 C43.0132469,41.9292302 43.7471604,40.6612585 44.7070339,39.6081331 C44.8549851,39.4457185 45.0941298,39.4088644 45.2829813,39.5193751 L46.9365778,40.4878771 C47.6323176,39.8833631 48.4321899,39.4143782 49.2959351,39.1045278 L49.2959351,37.1677994 C49.2959319,36.9465532 49.4471898,36.7548726 49.6600572,36.706368 C51.0174478,36.3972506 52.4752952,36.3812631 53.9011843,36.7060923 C54.1143687,36.7546454 54.266316,36.9461406 54.266316,37.1677207 L54.266316,39.1044884 C55.1300695,39.4143207 55.929945,39.8833074 56.6256733,40.4878377 L58.2792698,39.5193357 C58.4681214,39.4088251 58.7072661,39.4456791 58.8552172,39.6080937 C59.8150519,40.6612191 60.5490043,41.9291908 60.9788679,43.3327017 C61.0435999,43.544004 60.9558797,43.7727509 60.7668873,43.8834031 L59.1120093,44.8520626 C59.2782268,45.7657995 59.2782268,46.7026616 59.1120093,47.6163985 Z M54.8876185,46.2342305 C54.8876185,44.497188 53.4940371,43.0839902 51.7811062,43.0839902 C50.0681752,43.0839902 48.6745938,44.497188 48.6745938,46.2342305 C48.6745938,47.9712731 50.0681752,49.3844709 51.7811062,49.3844709 C53.4940371,49.3844709 54.8876185,47.9712731 54.8876185,46.2342305 Z M13.808,56.508 L12.524,56.508 L12.524,55.716 L16.034,55.716 L16.034,56.508 L14.75,56.508 L14.75,60 L13.808,60 L13.808,56.508 Z M16.526,55.716 L17.852,55.716 L18.854,58.662 L18.866,58.662 L19.814,55.716 L21.14,55.716 L21.14,60 L20.258,60 L20.258,56.964 L20.246,56.964 L19.196,60 L18.47,60 L17.42,56.994 L17.408,56.994 L17.408,60 L16.526,60 L16.526,55.716 Z"/>
+ </g>
+ </g>
+</svg>
diff --git a/addons/google_drive/static/src/css/google_drive.css b/addons/google_drive/static/src/css/google_drive.css
new file mode 100644
index 00000000..ce2b2259
--- /dev/null
+++ b/addons/google_drive/static/src/css/google_drive.css
@@ -0,0 +1,5 @@
+li.oe_share_gdoc > a:after {
+ content: url('/google_drive/static/src/img/drive_icon.png');
+ position: absolute;
+ right: 5px;
+}
diff --git a/addons/google_drive/static/src/img/drive_icon.png b/addons/google_drive/static/src/img/drive_icon.png
new file mode 100644
index 00000000..1553aa31
--- /dev/null
+++ b/addons/google_drive/static/src/img/drive_icon.png
Binary files differ
diff --git a/addons/google_drive/static/src/img/drive_icon_mono.png b/addons/google_drive/static/src/img/drive_icon_mono.png
new file mode 100644
index 00000000..9fd836b6
--- /dev/null
+++ b/addons/google_drive/static/src/img/drive_icon_mono.png
Binary files differ
diff --git a/addons/google_drive/static/src/js/gdrive.js b/addons/google_drive/static/src/js/gdrive.js
new file mode 100644
index 00000000..d6090aa9
--- /dev/null
+++ b/addons/google_drive/static/src/js/gdrive.js
@@ -0,0 +1,93 @@
+odoo.define('google_drive.ActionMenus', function (require) {
+ "use strict";
+
+ const ActionMenus = require('web.ActionMenus');
+ const DropdownMenuItem = require('web.DropdownMenuItem');
+
+ /**
+ * Fetches the google drive action menu item props. To do so this function
+ * is given its parent props and env, as well as the RPC function bound to
+ * the parent context.
+ * Note that we use the bound RPC to benefit from its added behaviour (see
+ * web/component_extension).
+ * @param {Object} props
+ * @param {number[]} props.activeIds
+ * @param {Object} props.context
+ * @param {Object} env
+ * @param {Object} env.action The current action
+ * @param {Object} env.view The current view
+ * @param {Function} rpc Bound to the ActionMenus context
+ * @returns {Object | boolean} item props or false
+ */
+ async function googleDrivePropsGetter(props, env, rpc) {
+ const [activeId] = props.activeIds;
+ const { context } = props;
+ if (env.view.type !== "form" || !activeId) {
+ return false;
+ }
+ const items = await rpc({
+ args: [env.action.res_model, activeId],
+ context,
+ method: 'get_google_drive_config',
+ model: 'google.drive.config',
+ });
+ return Boolean(items.length) && { activeId, context, items };
+ }
+
+ /**
+ * Google drive menu
+ *
+ * This component is actually a set of list items used to enrich the ActionMenus's
+ * "Action" dropdown list (@see ActionMenus). It will fetch
+ * the current user's google drive configuration and set the result as its
+ * items if any.
+ * @extends DropdownMenuItem
+ */
+ class GoogleDriveMenu extends DropdownMenuItem {
+
+ //---------------------------------------------------------------------
+ // Handlers
+ //---------------------------------------------------------------------
+
+ /**
+ * @private
+ * @param {number} itemId
+ * @returns {Promise}
+ */
+ async _onGoogleDocItemClick(itemId) {
+ const resID = this.props.activeId;
+ const domain = [['id', '=', itemId]];
+ const fields = ['google_drive_resource_id', 'google_drive_client_id'];
+ const configs = await this.rpc({
+ args: [domain, fields],
+ method: 'search_read',
+ model: 'google.drive.config',
+ });
+ const url = await this.rpc({
+ args: [itemId, resID, configs[0].google_drive_resource_id],
+ context: this.props.context,
+ method: 'get_google_drive_url',
+ model: 'google.drive.config',
+ });
+ if (url) {
+ window.open(url, '_blank');
+ }
+ }
+ }
+ GoogleDriveMenu.props = {
+ activeId: Number,
+ context: Object,
+ items: {
+ type: Array,
+ element: Object,
+ },
+ };
+ GoogleDriveMenu.template = 'GoogleDriveMenu';
+
+ ActionMenus.registry.add('google-drive-menu', {
+ Component: GoogleDriveMenu,
+ getProps: googleDrivePropsGetter,
+ });
+
+ return GoogleDriveMenu;
+});
diff --git a/addons/google_drive/static/src/xml/gdrive.xml b/addons/google_drive/static/src/xml/gdrive.xml
new file mode 100644
index 00000000..d12b3459
--- /dev/null
+++ b/addons/google_drive/static/src/xml/gdrive.xml
@@ -0,0 +1,14 @@
+<templates>
+ <t t-name="GoogleDriveMenu" owl="1">
+ <li>
+ <ul class="o_embed_menu">
+ <li t-foreach="props.items" t-as="gdriveItem" t-key="gdriveItem.id"
+ role="menuitem"
+ class="o_menu_item oe_share_gdoc_item dropdown-item"
+ >
+ <a href="#" t-esc="gdriveItem.name" t-on-click.prevent="_onGoogleDocItemClick(gdriveItem.id)"/>
+ </li>
+ </ul>
+ </li>
+ </t>
+</templates>
diff --git a/addons/google_drive/static/tests/gdrive_test.js b/addons/google_drive/static/tests/gdrive_test.js
new file mode 100644
index 00000000..3c684f8d
--- /dev/null
+++ b/addons/google_drive/static/tests/gdrive_test.js
@@ -0,0 +1,154 @@
+odoo.define('google_drive.gdrive_integration', function (require) {
+ "use strict";
+
+ const FormView = require('web.FormView');
+ const testUtils = require('web.test_utils');
+
+ const cpHelpers = testUtils.controlPanel;
+
+ QUnit.module('Google Drive Integration', {
+ beforeEach() {
+ this.data = {
+ partner: {
+ fields: {
+ display_name: { string: "Displayed name", type: "char", searchable: true },
+ },
+ records: [
+ { id: 1, display_name: "Locomotive Breath" },
+ { id: 2, display_name: "Hey Macarena" },
+ ],
+ },
+ };
+ },
+ }, function () {
+
+ QUnit.module('Google Drive ActionMenus');
+
+ QUnit.test('rendering of the google drive attachments in action menus', async function (assert) {
+ assert.expect(3);
+
+ const form = await testUtils.createView({
+ actionMenusRegistry: true,
+ arch:
+ `<form string="Partners">
+ <field name="display_name"/>
+ </form>`,
+ data: this.data,
+ async mockRPC(route, args) {
+ switch (route) {
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
+ assert.deepEqual(args.args, ['partner', 1],
+ 'The route to get google drive config should have been called');
+ return [{
+ id: 27,
+ name: 'Cyberdyne Systems',
+ }];
+ case '/web/dataset/call_kw/google.drive.config/search_read':
+ return [{
+ google_drive_resource_id: "T1000",
+ google_drive_client_id: "cyberdyne.org",
+ id: 1,
+ }];
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
+ assert.deepEqual(args.args, [27, 1, 'T1000'],
+ 'The route to get the Google url should have been called');
+ return; // do not return anything or it will open a new tab.
+ }
+ },
+ model: 'partner',
+ res_id: 1,
+ View: FormView,
+ viewOptions: {
+ hasActionMenus: true,
+ },
+ });
+ await cpHelpers.toggleActionMenu(form);
+
+ assert.containsOnce(form, '.oe_share_gdoc_item',
+ "The button to the google action should be present");
+
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
+
+ form.destroy();
+ });
+
+ QUnit.test("no google drive data", async function (assert) {
+ assert.expect(1);
+
+ const form = await testUtils.createView({
+ actionMenusRegistry: true,
+ arch:
+ `<form string="Partners">
+ <field name="display_name"/>
+ </form>`,
+ data: this.data,
+ model: 'partner',
+ res_id: 1,
+ View: FormView,
+ viewOptions: {
+ hasActionMenus: true,
+ ids: [1, 2],
+ index: 0,
+ },
+ });
+
+ assert.containsNone(form, ".o_cp_action_menus .o_embed_menu");
+
+ form.destroy();
+ });
+
+ QUnit.test('click on the google drive attachments after switching records', async function (assert) {
+ assert.expect(4);
+
+ let currentRecordId = 1;
+ const form = await testUtils.createView({
+ actionMenusRegistry: true,
+ arch:
+ `<form string="Partners">
+ <field name="display_name"/>
+ </form>`,
+ data: this.data,
+ async mockRPC(route, args) {
+ switch (route) {
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_config':
+ assert.deepEqual(args.args, ['partner', currentRecordId],
+ 'The route to get google drive config should have been called');
+ return [{
+ id: 27,
+ name: 'Cyberdyne Systems',
+ }];
+ case '/web/dataset/call_kw/google.drive.config/search_read':
+ return [{
+ google_drive_resource_id: "T1000",
+ google_drive_client_id: "cyberdyne.org",
+ id: 1,
+ }];
+ case '/web/dataset/call_kw/google.drive.config/get_google_drive_url':
+ assert.deepEqual(args.args, [27, currentRecordId, 'T1000'],
+ 'The route to get the Google url should have been called');
+ return; // do not return anything or it will open a new tab.
+ }
+ },
+ model: 'partner',
+ res_id: 1,
+ View: FormView,
+ viewOptions: {
+ hasActionMenus: true,
+ ids: [1, 2],
+ index: 0,
+ },
+ });
+
+ await cpHelpers.toggleActionMenu(form);
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
+
+ currentRecordId = 2;
+ await cpHelpers.pagerNext(form);
+
+ await cpHelpers.toggleActionMenu(form);
+ await cpHelpers.toggleMenuItem(form, "Cyberdyne Systems");
+
+ form.destroy();
+ });
+ });
+});
diff --git a/addons/google_drive/static/tests/mock_server.js b/addons/google_drive/static/tests/mock_server.js
new file mode 100644
index 00000000..5fb190e3
--- /dev/null
+++ b/addons/google_drive/static/tests/mock_server.js
@@ -0,0 +1,22 @@
+odoo.define('google_drive.MockServer', function (require) {
+ 'use strict';
+
+ var MockServer = require('web.MockServer');
+
+ MockServer.include({
+ //--------------------------------------------------------------------------
+ // Private
+ //--------------------------------------------------------------------------
+
+ /**
+ * @override
+ * @private
+ */
+ async _performRpc(route, args) {
+ if (args.method === 'get_google_drive_config') {
+ return [];
+ }
+ return this._super(...arguments);
+ },
+ });
+});