Skip to content

Commit

Permalink
MBS-9493: Fix failing checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Garske committed Nov 14, 2024
1 parent b9c8d1f commit ad06ce5
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 43 deletions.
2 changes: 0 additions & 2 deletions amd/src/ai_manager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {makeRequest} from 'local_ai_manager/make_request';
import {exception as displayException} from 'core/notification';

/**
* Get the async answer from the local_ai_manager.
Expand All @@ -14,7 +13,6 @@ export const askLocalAiManager = async(purpose, prompt, options = []) => {
try {
result = await makeRequest(purpose, prompt, options);
} catch (error) {
console.log(error);
result.code = 'aiconnector';
result.result = error.error + " " + error.message;
// For devs.
Expand Down
18 changes: 2 additions & 16 deletions amd/src/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class DialogModal extends Modal {
modalConfig.removeOnClose = false;

modalConfig.isVerticallyCentered = false;
// returnFocus: target,

super.configure(modalConfig);

Expand Down Expand Up @@ -107,7 +106,6 @@ export const init = async(params) => {
templateContext: {
title: strNewDialog,
badge: badge,
// history: history, // history dynamically added.
},
});

Expand Down Expand Up @@ -232,12 +230,9 @@ async function showModal() {
* Webservice Get all conversations.
*/
const getConversations = async() => {
console.log("allConversations called");
try {
allConversations = await externalServices.getAllConversations(userid, contextid);
console.log(allConversations);
} catch (error) {
console.log(allConversations);
displayException(error);
}
};
Expand All @@ -247,7 +242,6 @@ const getConversations = async() => {
* @param {*} id
*/
const showConversation = (id = 0) => {
console.log("showConversation called");
// Dissallow changing conversations when question running.
if (aiAtWork) {
return;
Expand Down Expand Up @@ -284,7 +278,6 @@ const enterQuestion = async(question) => {
}
const message = await userAllowed();
if (message !== '') {
console.log("User not allowed");
const notice = await getString('noticenewquestion', 'block_ai_chat');
await displayAlert(notice, message);
aiAtWork = false;
Expand Down Expand Up @@ -363,7 +356,7 @@ const enterQuestion = async(question) => {
* Render reply.
* @param {string} text
*/
const showReply = async (text) => {
const showReply = async(text) => {
// Get textblock.
let fields = document.querySelectorAll('.ai_chat_modal .awaitanswer .text');
const field = fields[fields.length - 1];
Expand All @@ -378,7 +371,6 @@ const showReply = async (text) => {
};

const showMessages = () => {
console.log("showMessages called");
conversation.messages.forEach((val) => {
showMessage(val.message, val.sender);
});
Expand Down Expand Up @@ -427,7 +419,6 @@ const showMessage = async(text, sender = '', answer = true) => {
* @param {bool} deleted
*/
const newDialog = async(deleted = false) => {
console.log("newDialog called");
if (aiAtWork) {
return;
}
Expand All @@ -449,7 +440,6 @@ const newDialog = async(deleted = false) => {
* Delete /hide current dialog.
*/
const deleteCurrentDialog = () => {
console.log("deleteCurrentDialog called");
deleteCancelPromise(
getString('delete', 'block_ai_chat'),
getString('deletewarning', 'block_ai_chat'),
Expand All @@ -475,7 +465,6 @@ const deleteCurrentDialog = () => {
* Show conversation history.
*/
const showHistory = async() => {
console.log("showHistory called");
// Add current convo local representation, if not already there.
if (allConversations.find(x => x.id === conversation.id) === undefined) {
allConversations.push(conversation);
Expand Down Expand Up @@ -598,7 +587,6 @@ const saveConversationLocally = (question, reply) => {
* @param {*} hideinput
*/
const clearMessages = (hideinput = false) => {
console.log("clearMessages called");
const output = document.querySelector('.block_ai_chat-output');
output.innerHTML = '';
// For showing history.
Expand Down Expand Up @@ -727,7 +715,6 @@ const errorHandling = async(requestresult, question, options) => {

// And write generic error message in chatbot.
requestresult.result = await getString('error', 'block_ai_chat');
console.log(requestresult);
return requestresult;
};

Expand All @@ -738,11 +725,9 @@ const errorHandling = async(requestresult, question, options) => {
*/
const checkMessageHistoryLengthLimit = async(messages) => {
const length = messages.length;
console.log("checkHistoryLengthLimit called");
if (length > maxHistory) {
// Cut history.
let shortenedMessages = [messages[0], ...messages.slice(-maxHistory)];
console.log(shortenedMessages);

// Show warning once per session.
if (!maxHistoryWarnings.has(conversation.id)) {
Expand Down Expand Up @@ -800,6 +785,7 @@ const setView = async(mode = '') => {
* @returns {message}
*/
const userAllowed = async() => {
let message;
if (tenantConfig.tenantenabled === false) {
message = await getString('error_http403disabled', 'local_ai_manager');
return message;
Expand Down
3 changes: 1 addition & 2 deletions amd/src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const focustextarea = () => {
* Scroll to bottom of modal body.
*/
export const scrollToBottom = () => {
console.log("scroll to bottom called");
const modalContent = document.querySelector('.ai_chat_modal .modal-body .block_ai_chat-output-wrapper');
modalContent.scrollTop = modalContent.scrollHeight;
};
Expand All @@ -71,7 +70,7 @@ export const escapeHTML = (str) => {
'/': '/',
};

return String(str).replace(/[&<>"'`\/]/g, function(match) {
return String(str).replace(/[&<>"'`/]/g, function(match) {
return escapeMap[match];
});
};
Expand Down
2 changes: 2 additions & 0 deletions classes/external/delete_conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public static function execute_parameters(): external_function_parameters {
* Execute the service.
*
* @param int $contextid
* @param int $userid
* @param int $conversationid
* @return array
* @throws invalid_parameter_exception
* @throws dml_exception
Expand Down
4 changes: 3 additions & 1 deletion classes/local/hook_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public static function handle_after_form_submission(\core_course\hook\after_form
/**
* Check if block instance is present and set addaichat form setting.
*
* @param after_form_submission $hook
* @param after_form_definition_after_data $hook
* @return void
* @throws \dml_exception
*/
public static function handle_after_form_definition_after_data(\core_course\hook\after_form_definition_after_data $hook): void {
// Get form data.
Expand Down
1 change: 1 addition & 0 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class renderer extends plugin_renderer_base {
/**
* Defer to template.
*
* @param block_ai_chat $block
* @return string html for the page
*/
public function render_ai_chat_content(\block_ai_chat $block): string {
Expand Down
14 changes: 8 additions & 6 deletions styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* stylelint-disable */
#ai_chat_button {
visibility: visible;
position: fixed;
Expand Down Expand Up @@ -256,6 +257,11 @@
display: none;
}

@media (min-width: 497px) {
.ai_chat_modal.onhistorypage .modal-body {
min-width: 497px;
}
}
.ai_fake_block {
visibility: hidden;
height: 0;
Expand All @@ -277,7 +283,8 @@ body.block_ai_chat_chatwindow,
body.block_ai_chat_dockright {
overflow: initial;
}
body.block_ai_chat_chatwindow .modal-backdrop.show, body.block_ai_chat_chatwindow .ai_chat_modal,
body.block_ai_chat_chatwindow .modal-backdrop.show,
body.block_ai_chat_chatwindow .ai_chat_modal,
body.block_ai_chat_dockright .modal-backdrop.show,
body.block_ai_chat_dockright .ai_chat_modal {
width: 0;
Expand Down Expand Up @@ -330,11 +337,6 @@ body.block_ai_chat_openfull .block_floatingbutton-floatingicons {
display: none;
}
}
@media (min-width: 497px) {
.ai_chat_modal.onhistorypage .modal-body {
min-width: 497px;
}
}
body.block_ai_chat_replacehelp #page-footer [data-region=footer-container-popover] .btn-footer-popover[data-action=footer-popover] {
display: none;
}
Expand Down
20 changes: 11 additions & 9 deletions styles.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* stylelint-disable */
#ai_chat_button {
visibility: visible;
position: fixed;
Expand Down Expand Up @@ -269,7 +270,13 @@
}
}
}

@media (min-width: 497px) {
.ai_chat_modal.onhistorypage {
.modal-body {
min-width: 497px;
}
}
}

.ai_fake_block {
visibility: hidden;
Expand All @@ -292,7 +299,8 @@ body.block_ai_chat_chatwindow {
body.block_ai_chat_chatwindow,
body.block_ai_chat_dockright {
overflow: initial;
.modal-backdrop.show, .ai_chat_modal {
.modal-backdrop.show,
.ai_chat_modal {
width: 0;
height: 0;
}
Expand Down Expand Up @@ -349,13 +357,7 @@ body.block_ai_chat_openfull {
display: none;
}
}
@media (min-width: 497px) {
.ai_chat_modal.onhistorypage {
.modal-body {
min-width: 497px;
}
}
}


body.block_ai_chat_replacehelp {
// Replace question mark popover on the bottom right corner with ai_chat.
Expand Down
4 changes: 2 additions & 2 deletions templates/dialog_modal.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template block_ai_chat/iconpicker
@template block_ai_chat/dialog_modal
Template for iconpicker.
Expand All @@ -32,7 +32,7 @@ along with Moodle. If not, see <http://www.gnu.org/licenses/>.
{
"history": {
"message":"content",
"sender":"user",
"sender":"user"
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion templates/floatingbutton.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Example context (json):
{
"title":"AI Companion",
"arialabel":"Open AI Companion",
"arialabel":"Open AI Companion"
}
}}
<button title="{{title}}" class="btn btn-icon icon-size-3" id="ai_chat_button"
Expand Down
4 changes: 2 additions & 2 deletions templates/history.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"key": "Heute",
"objects": [{
"title": "Erste Frage",
"conversationid": 9,
},]
"conversationid": 9
}]
}
}}

Expand Down
4 changes: 2 additions & 2 deletions templates/message.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template block_ai_chat/floatingbutton
@template block_ai_chat/message
Button to call ai_chat modal
Example context (json):
{
"message":"content",
"sender":"",
"sender":""
}
}}
{{! Show message from user or ai }}
Expand Down

0 comments on commit ad06ce5

Please sign in to comment.