Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration des fonctions weda comme les notifications et les capabilities #252

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions FW_scripts/FWData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let weda = window.weda || {};

let infos = {
wedaHelper: weda.wedaHelper,
capabilities: weda.capabilities
}

window.postMessage({
type: "FROM_PAGE",
payload: infos
}, "*");
13 changes: 13 additions & 0 deletions FW_scripts/FWNotif.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// fichier de Fonction Weda de notification

// ce fichier doit être static car le navigateur
// ne veut pas utiliser des fichiers en one-line
let weda = window.weda || {};

weda.actions.showNotification({
message: "Notification de test", // message displayed
icon: "home", // mat icon used for the notification
type: "success", // color (success / fail / undefined)
extra: {}, // extra data (json)
duration: 5000 // duration of the notification
});
85 changes: 85 additions & 0 deletions FW_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# FW - scripts

FW pour "Fonctions Weda"

Voici un petit tuto pour utiliser une fonction weda tout d'abord allez sur secure, ouvrez une console commencez a taper : `window.weda.`.

L'auto-complétion sera proposée par le navigateur.

### exemple
![exemple](./image.png)


# Variables
Des variables ont été ajoutées pour savoir si weda a activé certaines fonctionnalités.

dans `window.weda.wedaHelper` :

- courbesPediatrie
- historiqueConsultation

dans `window.weda.capabilities`:

- hasDmp
- hasCda
- hasInterop
- hasWedaConnect
- hasNotifications
- hasSegur
- etc ...

*Feel free to do something with it* (on ne peut pas les modifier).

Dans `window.weda.actions` nous avons tout un tas de fonctions, notamment le `sendNotification()` (qui permet d'envoyer des notifications ... toujours utile ... *feel free to do something with it*).

En revanche il est difficile d'envoyer des notifications avec des messages customs dans le cadre de l'extension chrome (donc un fichier .js par notification).

Pour utiliser un fichier "FW", voici un example :

```js

// content script

function useFWScript() {
var script = document.createElement('script'); // nouvelle balise
script.src = chrome.runtime.getURL('FW_scripts/FWData.js'); // feed
(document.head || document.documentElement).appendChild(script); // applique

// une fois l'enfant ajouté, le script va s'exécuter automatiquement.
// il n'est malheureusement pas possible de le rendre réutilisable
// donc il faudra ajouter un script par notification.

// ajouter la fonction dans un "script.innerText" n'est pas possible
// car on trigger les sécurités du navigateur.

// si notre script doit retourner des valeurs on vient l'intercepter
// avec un event Listener
window.addEventListener("message", function(event) {
console.log(event);
if (event.source === window && event.data.type === "FROM_PAGE") {
console.log("Données depuis la page : ", event.data.payload);
}
});
}
```

FWData.js associé:

```js
let weda = window.weda || {};

let infos = {
wedaHelper: weda.wedaHelper,
capabilities: weda.capabilities
}

// partie optionnelle (seulement si on veut renvoyer des infos)
window.postMessage({
type: "FROM_PAGE",
payload: infos
}, "*");
```

Je préfère ne pas m’avancer sur l'implementation final. mais voici le concept pour récupérer les valeurs mise a dispositions par WEDA pour ne pas avoir de features en doublons.

Par la meme occasion vous avez access au fonctionnalités du support pour reset / configurer les déférents composant de weda ;).
Binary file added FW_scripts/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,16 @@ addTweak('/FolderMedical/PopUpRappel.aspx', '*focusOnTextArea', function () {
});




/* === test d'implementation ... === */
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action === "sendNotif") {
let script = document.createElement('script');
script.src = chrome.runtime.getURL('FW_scripts/FWNotifv2.js?test=true');
console.log(script)
(document.head || document.documentElement).appendChild(script);
}
}
);
57 changes: 31 additions & 26 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
"name": "Weda Helper",
"version": "2.6.9.4",
"options_page": "options.html",
"permissions": ["storage"],
"host_permissions": ["http://localhost/"],
"permissions": [
"storage"
],
"host_permissions": [
"http://localhost/"
],
"action": {
"default_popup": "popup.html"
},
Expand All @@ -14,30 +18,31 @@
},
"content_scripts": [
{
"matches": ["*://secure.weda.fr/*"],
"matches": [
"*://secure.weda.fr/*"
],
"js": [
"metrics.js",
"lib/hotkeys.js",
"utils.js",
"content.js",
"tooltip.js",
"popupFunctions.js",
"patientLink.js",
"accueil.js",
"consultation.js",
"fse.js",
"keyCommands.js",
"searchUpload.js",
"companionLink.js",
"prescription.js",
"update.js",
"aati.js",
"upload.js",
"agenda.js",
"antecedent.js",
"print.js"]
"metrics.js",
"lib/hotkeys.js",
"utils.js",
"content.js",
"tooltip.js",
"popupFunctions.js",
"patientLink.js",
"accueil.js",
"consultation.js",
"fse.js",
"keyCommands.js",
"searchUpload.js",
"companionLink.js",
"prescription.js",
"update.js",
"aati.js",
"upload.js",
"agenda.js",
"antecedent.js",
"print.js"
]
}
]
}


}
4 changes: 4 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
<button id="sendCustomAmount">Envoyer au TPE</button>
<input type="number" id="customAmount" placeholder="Montant">
</div>
<div class="button-container">
<button id="sendNotif">Notif</button>
<span>envoie une notification de test</span>
</div>
<script src="popup.js"></script>
</body>
</html>
10 changes: 8 additions & 2 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const buttons = {
'allConsultation': 'allConsultation',
'tpebis': 'tpebis',
// Ajoutez d'autres boutons ici
'sendCustomAmount': 'sendCustomAmount'
'sendNotif': 'sendNotif',
'sendCustomAmount': 'sendCustomAmount',
};

for (let id in buttons) {
Expand All @@ -15,6 +16,10 @@ for (let id in buttons) {
chrome.tabs.sendMessage(tabs[0].id, {action: buttons[id], amount: customAmount});
});
console.log(buttons[id] + " message sent with amount: " + customAmount);
} else if (id === 'sendNotif') {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {action: buttons[id]});
});
} else {
console.log("No amount entered");
}
Expand All @@ -25,4 +30,5 @@ for (let id in buttons) {
console.log(buttons[id] + " message sent");
}
});
}
}