diff --git a/src/App.js b/src/App.js index 1eccac4..ef9ca04 100644 --- a/src/App.js +++ b/src/App.js @@ -11,10 +11,7 @@ import './App.css'; import { ThemeProvider, createMuiTheme } from '@material-ui/core/styles'; -import Navbar from './components/Navbar'; -import Footer from './components/Footer'; -import Routes from './components/Route/Routes'; -import Cookies from './components/Cookies'; +import Content from './components/Content'; const theme = createMuiTheme({ palette: { @@ -43,12 +40,7 @@ class App extends Component { -
- - - -
-
+
diff --git a/src/actions/authActions.js b/src/actions/authActions.js index b5d6531..2da6b9e 100644 --- a/src/actions/authActions.js +++ b/src/actions/authActions.js @@ -1,8 +1,8 @@ import { MYBADGES_CONNECT, MYBADGES_DISCONNECT, GET_STATUS, USER_LOADED, USER_LOADING, AUTH_ERROR, LOGIN_SUCCESS, LOGIN_FAIL, LOGOUT_SUCCESS, LOGOUT_FAIL, REFRESH_TOKEN_SUCCESS } from '../actions/types'; import axios from 'axios'; -import { returnErrors, returnSuccess } from './messageActions' - +import { returnErrors, returnSuccess } from './messageActions'; +import { setLanguage } from './generalActions'; // Check token & load user export const loadUser = () => (dispatch) => { @@ -20,6 +20,7 @@ export const loadUser = () => (dispatch) => { type: USER_LOADED, payload: res.data.user }); + dispatch(setLanguage(res.data.user.language)); }, error: err => { if(err.response){ @@ -77,6 +78,7 @@ export const login = ({ email, password }) => (dispatch) => { type: GET_STATUS, payload: res.data.user.status }); + dispatch(setLanguage(res.data.user.language)); dispatch(returnSuccess(res.data.message, res.status, 'LOGIN_SUCCESS')); }) .catch(err => { @@ -170,6 +172,11 @@ export const logout = () => (dispatch) => { type: GET_STATUS, payload: status }); + var locale = 'de_DE'; + if (window.localStorage.getItem('locale')) { + locale = window.localStorage.getItem('locale'); + } + dispatch(setLanguage(locale)); dispatch(returnSuccess(res.data.message, res.status, 'LOGOUT_SUCCESS')); clearTimeout(logoutTimerId); }, diff --git a/src/actions/generalActions.js b/src/actions/generalActions.js index 6585a9a..6d1838b 100644 --- a/src/actions/generalActions.js +++ b/src/actions/generalActions.js @@ -1,4 +1,4 @@ -import { VISIT } from './types'; +import { VISIT, LANGUAGE, RENDERER, STATISTICS } from './types'; export const visitPage = () => (dispatch) => { @@ -6,3 +6,27 @@ export const visitPage = () => (dispatch) => { type: VISIT }); }; + +export const setLanguage = (language) => (dispatch, getState) => { + if(!getState().auth.isAuthenticated){ + window.localStorage.setItem('locale', language); + } + dispatch({ + type: LANGUAGE, + payload: language + }); +}; + +export const setRenderer = (renderer) => (dispatch) => { + dispatch({ + type: RENDERER, + payload: renderer + }); +}; + +export const setStatistics = (showStatistics) => (dispatch) => { + dispatch({ + type: STATISTICS, + payload: showStatistics + }); +}; diff --git a/src/actions/projectActions.js b/src/actions/projectActions.js index 149584d..6caef34 100644 --- a/src/actions/projectActions.js +++ b/src/actions/projectActions.js @@ -1,7 +1,6 @@ import { PROJECT_PROGRESS, GET_PROJECT, GET_PROJECTS, PROJECT_TYPE, PROJECT_DESCRIPTION } from './types'; import axios from 'axios'; -import { workspaceName } from './workspaceActions'; import { returnErrors, returnSuccess } from './messageActions'; export const setType = (type) => (dispatch) => { @@ -19,13 +18,13 @@ export const setDescription = (description) => (dispatch) => { }; export const getProject = (type, id) => (dispatch) => { - dispatch({type: PROJECT_PROGRESS}); + dispatch({ type: PROJECT_PROGRESS }); dispatch(setType(type)); const config = { success: res => { var data = type === 'share' ? 'content' : type; var project = res.data[data]; - if(project){ + if (project) { dispatch({ type: GET_PROJECT, payload: project @@ -34,11 +33,11 @@ export const getProject = (type, id) => (dispatch) => { type: PROJECT_DESCRIPTION, payload: project.description }); - dispatch({type: PROJECT_PROGRESS}); + dispatch({ type: PROJECT_PROGRESS }); dispatch(returnSuccess(res.data.message, res.status, 'GET_PROJECT_SUCCESS')); } - else{ - dispatch({type: PROJECT_PROGRESS}); + else { + dispatch({ type: PROJECT_PROGRESS }); dispatch(returnErrors(res.data.message, res.status, 'PROJECT_EMPTY')); } }, @@ -68,7 +67,7 @@ export const getProjects = (type) => (dispatch) => { type: GET_PROJECTS, payload: projects }); - dispatch({type: PROJECT_PROGRESS}); + dispatch({ type: PROJECT_PROGRESS }); dispatch(returnSuccess(res.data.message, res.status)); }, error: err => { @@ -94,7 +93,7 @@ export const updateProject = (type, id) => (dispatch, getState) => { title: workspace.name }; var project = getState().project; - if(type==='gallery'){ + if (type === 'gallery') { body.description = project.description; } const config = { @@ -107,7 +106,7 @@ export const updateProject = (type, id) => (dispatch, getState) => { type: GET_PROJECTS, payload: projects }); - if(type === 'project'){ + if (type === 'project') { dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_UPDATE_SUCCESS')); } else { dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_UPDATE_SUCCESS')); @@ -143,7 +142,7 @@ export const deleteProject = (type, id) => (dispatch, getState) => { type: GET_PROJECTS, payload: projects }); - if(type === 'project'){ + if (type === 'project') { dispatch(returnSuccess(res.data.message, res.status, 'PROJECT_DELETE_SUCCESS')); } else { dispatch(returnSuccess(res.data.message, res.status, 'GALLERY_DELETE_SUCCESS')); @@ -169,7 +168,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => { var body = { title: title }; - if(type === 'project'){ + if (type === 'project') { body.projectId = id; } else { body.xml = getState().workspace.code.xml; @@ -177,7 +176,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => { axios.post(`${process.env.REACT_APP_BLOCKLY_API}/share`, body) .then(res => { var shareContent = res.data.content; - if(body.projectId){ + if (body.projectId) { var projects = getState().project.projects; var index = projects.findIndex(res => res._id === id); projects[index].shared = shareContent.expiresAt; @@ -189,7 +188,7 @@ export const shareProject = (title, type, id) => (dispatch, getState) => { dispatch(returnSuccess(res.data.message, shareContent._id, 'SHARE_SUCCESS')); }) .catch(err => { - if(err.response){ + if (err.response) { dispatch(returnErrors(err.response.data.message, err.response.status, 'SHARE_FAIL')); } }); diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js index ee120ca..7a9801a 100644 --- a/src/actions/tutorialActions.js +++ b/src/actions/tutorialActions.js @@ -1,4 +1,4 @@ -import { MYBADGES_DISCONNECT, TUTORIAL_PROGRESS, GET_TUTORIAL, GET_TUTORIALS, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID, TUTORIAL_STEP } from './types'; +import { MYBADGES_DISCONNECT, TUTORIAL_PROGRESS, GET_TUTORIAL, GET_TUTORIALS, TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_STEP } from './types'; import axios from 'axios'; import { returnErrors, returnSuccess } from './messageActions'; @@ -12,15 +12,11 @@ export const getTutorial = (id) => (dispatch, getState) => { axios.get(`${process.env.REACT_APP_BLOCKLY_API}/tutorial/${id}`) .then(res => { var tutorial = res.data.tutorial; - console.log('status', getState().tutorial.status); existingTutorial(tutorial, getState().tutorial.status).then(status => { - console.log('progress',getState().auth.progress); - console.log('status'); dispatch({ type: TUTORIAL_SUCCESS, payload: status }); - console.log('eins'); dispatch(updateStatus(status)); dispatch({ type: GET_TUTORIAL, @@ -31,10 +27,10 @@ export const getTutorial = (id) => (dispatch, getState) => { }); }) .catch(err => { - if(err.response){ + if (err.response) { dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIAL_FAIL')); } - dispatch({type: TUTORIAL_PROGRESS}); + dispatch({ type: TUTORIAL_PROGRESS }); }); }; @@ -54,15 +50,15 @@ export const getTutorials = () => (dispatch, getState) => { type: GET_TUTORIALS, payload: tutorials }); - dispatch({type: TUTORIAL_PROGRESS}); + dispatch({ type: TUTORIAL_PROGRESS }); dispatch(returnSuccess(res.data.message, res.status)); }); }) .catch(err => { - if(err.response){ + if (err.response) { dispatch(returnErrors(err.response.data.message, err.response.status, 'GET_TUTORIALS_FAIL')); } - dispatch({type: TUTORIAL_PROGRESS}); + dispatch({ type: TUTORIAL_PROGRESS }); }); }; @@ -174,7 +170,7 @@ export const tutorialCheck = (status, step) => (dispatch, getState) => { console.log('drei'); dispatch(updateStatus(tutorialsStatus)); dispatch(tutorialChange()); - dispatch(returnSuccess('','','TUTORIAL_CHECK_SUCCESS')); + dispatch(returnSuccess('', '', 'TUTORIAL_CHECK_SUCCESS')); }; export const storeTutorialXml = (code) => (dispatch, getState) => { @@ -208,9 +204,9 @@ export const tutorialStep = (step) => (dispatch) => { }; -const existingTutorials = (tutorials, status) => new Promise(function(resolve, reject){ +const existingTutorials = (tutorials, status) => new Promise(function (resolve, reject) { var newstatus; - new Promise(function(resolve, reject){ + new Promise(function (resolve, reject) { var existingTutorialIds = tutorials.map((tutorial, i) => { existingTutorial(tutorial, status).then(status => { newstatus = status; @@ -228,7 +224,6 @@ const existingTutorials = (tutorials, status) => new Promise(function(resolve, r }); const existingTutorial = (tutorial, status) => new Promise(function(resolve, reject){ - console.log('st',status); var tutorialsId = tutorial._id; var statusIndex = status.findIndex(status => status._id === tutorialsId); if (statusIndex > -1) { diff --git a/src/actions/types.js b/src/actions/types.js index 99ed6a6..a5ab516 100644 --- a/src/actions/types.js +++ b/src/actions/types.js @@ -47,6 +47,9 @@ export const PROGRESS = 'PROGRESS'; export const VISIT = 'VISIT'; +export const LANGUAGE = 'LANGUAGE'; +export const RENDERER = 'RENDERER'; +export const STATISTICS = 'STATISTICS'; // messages export const GET_ERRORS = 'GET_ERRORS'; diff --git a/src/components/Blockly/BlocklyWindow.js b/src/components/Blockly/BlocklyWindow.js index f3c680d..aa9ce69 100644 --- a/src/components/Blockly/BlocklyWindow.js +++ b/src/components/Blockly/BlocklyWindow.js @@ -18,26 +18,14 @@ class BlocklyWindow extends Component { constructor(props) { super(props); this.simpleWorkspace = React.createRef(); - var locale = window.localStorage.getItem('locale'); - this.state = { - renderer: window.localStorage.getItem('renderer'), - }; - if (locale === null) { - if (navigator.language === 'de-DE') { - locale = 'de'; - } else { - locale = 'en'; - } - } - if (locale === 'de') { + if (this.props.language === 'de_DE') { Blockly.setLocale(De); - } else if (locale === 'en') { + } else if (this.props.language === 'en_US') { Blockly.setLocale(En); } } componentDidMount() { - const workspace = Blockly.getMainWorkspace(); this.props.onChangeWorkspace({}); this.props.clearStats(); @@ -72,7 +60,7 @@ class BlocklyWindow extends Component { style={this.props.svg ? { height: 0 } : this.props.blocklyCSS} readOnly={this.props.readOnly !== undefined ? this.props.readOnly : false} trashcan={this.props.trashcan !== undefined ? this.props.trashcan : true} - renderer={this.state.renderer} + renderer={this.props.renderer} zoom={{ // https://developers.google.com/blockly/guides/configure/web/zoom controls: this.props.zoomControls !== undefined ? this.props.zoomControls : true, wheel: false, @@ -106,8 +94,14 @@ class BlocklyWindow extends Component { BlocklyWindow.propTypes = { onChangeWorkspace: PropTypes.func.isRequired, - clearStats: PropTypes.func.isRequired + clearStats: PropTypes.func.isRequired, + renderer: PropTypes.string.isRequired, + language: PropTypes.string.isRequired }; +const mapStateToProps = state => ({ + renderer: state.general.renderer, + language: state.general.language +}); -export default connect(null, { onChangeWorkspace, clearStats })(BlocklyWindow); +export default connect(mapStateToProps, { onChangeWorkspace, clearStats })(BlocklyWindow); diff --git a/src/components/Blockly/blocks/sensebox-osem.js b/src/components/Blockly/blocks/sensebox-osem.js index 144d00d..b744835 100644 --- a/src/components/Blockly/blocks/sensebox-osem.js +++ b/src/components/Blockly/blocks/sensebox-osem.js @@ -138,6 +138,12 @@ Blockly.Blocks['sensebox_send_to_osem'] = { } console.log(dropdown) } + if (dropdown.length > 1) { + var options = dropdown.slice(1) + return options + } else { + return dropdown + } } return dropdown }, diff --git a/src/components/Blockly/msg/de.js b/src/components/Blockly/msg/de.js index 2dec197..83207d7 100644 --- a/src/components/Blockly/msg/de.js +++ b/src/components/Blockly/msg/de.js @@ -800,4 +800,199 @@ Blockly.Msg.senseBox_mqtt_password = "Passwort"; Blockly.Msg.sensebox_mqtt_subscribe = "Subscribe to Feed" Blockly.Msg.senseBox_mqtt_publish = "Sende an Feed/Topic"; + + +/** + * Typed Variable Modal + * + */ + + +Blockly.Msg.TYPED_VAR_MODAL_CONFIRM_BUTTON = "Ok"; +Blockly.Msg.TYPED_VAR_MODAL_VARIABLE_NAME_LABEL = "Variablen Name: "; +Blockly.Msg.TYPED_VAR_MODAL_TYPES_LABEL = "Variable Typen"; +Blockly.Msg.TYPED_VAR_MODAL_CANCEL_BUTTON = "Abbrechen"; +Blockly.Msg.TYPED_VAR_MODAL_TITLE = "Erstelle Variable"; +Blockly.Msg.TYPED_VAR_MODAL_INVALID_NAME = "Der Name ist ungültig, bitte versuche einen anderen." + +/** + * Add Translation for Blocks above + * --------------------------------------------------------------- + * Add Translation for the UI below + */ + +/** + * Toolbox + */ +Blockly.Msg.toolbox_sensors = "Sensoren"; +Blockly.Msg.toolbox_logic = "Logik"; +Blockly.Msg.toolbox_loops = "Schleifen"; +Blockly.Msg.toolbox_math = "Mathematik"; +Blockly.Msg.toolbox_io = "Eingang/Ausgang"; +Blockly.Msg.toolbox_time = "Zeit"; +Blockly.Msg.toolbox_functions = "Funktionen"; +Blockly.Msg.toolbox_variables = "Variablen"; + +/** + * Tooltips + * + */ + +Blockly.Msg.tooltip_compile_code = "Code kompilieren" +Blockly.Msg.tooltip_save_blocks = "Blöcke speichern"; +Blockly.Msg.tooltip_open_blocks = "Blöcke öffnen"; +Blockly.Msg.tooltip_screenshot = "Screenshot erstellen"; +Blockly.Msg.tooltip_clear_workspace = "Workspace zurücksetzen"; +Blockly.Msg.tooltip_share_blocks = "Blöcke teilen"; +Blockly.Msg.tooltip_show_code = "Code anzeigen"; +Blockly.Msg.tooltip_hide_code = "Code ausblenden" +Blockly.Msg.tooltip_delete_project = "Projekt löschen" +Blockly.Msg.tooltip_project_name = "Name des Projektes" +Blockly.Msg.tooltip_download_project = "Projekt herunterladen" +Blockly.Msg.tooltip_open_project = "Projekt öffnen" +Blockly.Msg.tooltip_update_project = "Projekt aktualisieren" +Blockly.Msg.tooltip_save_project = "Projekt speichern" +Blockly.Msg.tooltip_create_project = "Projekt erstellen" +Blockly.Msg.tooltip_share_project = "Projekt teilen" +Blockly.Msg.tooltip_reset_workspace = "Workspace zurücksetzen" +Blockly.Msg.tooltip_copy_link = "Link kopieren" +Blockly.Msg.tooltip_trashcan_hide = 'gelöschte Blöcke ausblenden' +Blockly.Msg.tooltip_trashcan_delete = 'Blöcke endgültig löschen' +Blockly.Msg.tooltip_project_title = "Titel des Projektes" +Blockly.Msg.tooltip_check_solution = "Lösung kontrollieren" + +/** + * Messages + * + */ + +Blockly.Msg.messages_delete_project_failed = "Fehler beim Löschen des Projektes. Versuche es noch einmal." +Blockly.Msg.messages_reset_workspace_success = "Das Projekt wurde erfolgreich zurückgesetzt" +Blockly.Msg.messages_PROJECT_UPDATE_SUCCESS = "Das Projekt wurde erfolgreich aktualisiert." +Blockly.Msg.messages_GALLERY_UPDATE_SUCCESS = "Das Galerie-Projekt wurde erfolgreich aktualisiert." +Blockly.Msg.messages_PROJECT_UPDATE_FAIL = "Fehler beim Aktualisieren des Projektes. Versuche es noch einmal." +Blockly.Msg.messages_GALLERY_UPDATE_FAIL = "Fehler beim Aktualisieren des Galerie-Projektes. Versuche es noch einmal." +Blockly.Msg.messages_gallery_save_fail_1 = "Fehler beim Speichern des " +Blockly.Msg.messages_gallery_save_fail_2 = "Projektes. Versuche es noch einmal." +Blockly.Msg.messages_SHARE_SUCCESS = 'Programm teilen' +Blockly.Msg.messages_SHARE_FAIL = "Fehler beim Erstellen eines Links zum Teilen deines Programmes. Versuche es noch einmal." +Blockly.Msg.messages_copylink_success = 'Link erfolgreich in Zwischenablage gespeichert.' +Blockly.Msg.messages_rename_success_01 = 'Das Projekt wurde erfolgreich in ' +Blockly.Msg.messages_rename_success_02 = 'umbenannt.' +Blockly.Msg.messages_newblockly_head = "Willkommen zur neuen Version Blockly für die senseBox" +Blockly.Msg.messages_newblockly_text = "Die neue Blockly Version befindet sich zurzeit in der Testphase. Alle Neuigkeiten findet ihr hier:" +Blockly.Msg.messages_GET_TUTORIAL_FAIL = 'Zurück zur Tutorials-Übersicht' +Blockly.Msg.messages_LOGIN_FAIL = 'Der Benutzername oder das Passwort ist nicht korrekt.' +/** + * Share Dialog + */ + +Blockly.Msg.sharedialog_headline = "Dein Link wurde erstellt."; +Blockly.Msg.sharedialog_text = "Über den folgenden Link kannst du dein Programm teilen."; + +/** + * Project rename Dialog + */ + +Blockly.Msg.renamedialog_headline = "Projekt benennen"; +Blockly.Msg.renamedialog_text = "Bitte gib einen Namen für das Projekt ein und bestätige diesen mit einem Klick auf 'Bestätigen'." + +/** + * Compile Dialog + * + */ + +Blockly.Msg.compiledialog_headline = "Fehler" +Blockly.Msg.compiledialog_text = "Beim kompilieren ist ein Fehler aufgetreten. Überprüfe deine Blöcke und versuche es erneut" + +/** + * Buttons + * + */ + +Blockly.Msg.button_cancel = "Abbrechen"; +Blockly.Msg.button_close = "Schließen"; +Blockly.Msg.button_accept = "Bestätigen"; +Blockly.Msg.button_compile = "Kompilieren"; +Blockly.Msg.button_create_variableCreate = "Erstelle Variable"; +Blockly.Msg.button_back = "Zurück" +Blockly.Msg.button_next = "nächster Schritt" +Blockly.Msg.button_tutorial_overview = "Tutorial Übersicht" + + +/** + * + */ + +Blockly.Msg.filename = "Dateiname"; +Blockly.Msg.projectname = "Projektname"; + +/** + * Settings + */ +Blockly.Msg.settings_head = "Einstellungen" +Blockly.Msg.settings_language = "Sprache" +Blockly.Msg.settings_language_text = "Auswahl der Sprache gilt für die gesamte Anwendung. Es kann zwischen Deutsch und Englisch unterschieden werden." +Blockly.Msg.settings_language_de = "Deutsch" +Blockly.Msg.settings_language_en = "Englisch" +Blockly.Msg.settings_renderer = "Renderer" +Blockly.Msg.settings_renderer_text = "Der eingestellte Renderer bestimmt das Aussehen der Blöcke. Es kann zwischen 'Geras' und 'Zelos' unterschieden werden, wobei 'Zelos' insbesondere für eine Touch-Anwendung geeignet ist." +Blockly.Msg.settings_statistics = "Statistiken" +Blockly.Msg.settings_statistics_text = "Die Anzeige von Statistiken zur Nutzung der Blöcke oberhalb der Arbeitsfläche kann ein- oder ausgeblendet werden." +Blockly.Msg.settings_statistics_on = "An" +Blockly.Msg.settings_statistics_off = "Aus" + +/** + * 404 + */ + +Blockly.Msg.notfound_head = "Die von Ihnen angeforderte Seite kann nicht gefunden werden." +Blockly.Msg.notfound_text = "Die gesuchte Seite wurde möglicherweise entfernt, ihr Name wurde geändert oder sie ist vorübergehend nicht verfügbar." + + +/** + * Labels + */ + +Blockly.Msg.labels_donotshowagain = 'Dialog nicht mehr anzeigen' +Blockly.Msg.labels_here = "hier" +Blockly.Msg.labels_username = 'E-Mail oder Nutzername' + +/** + * Badges + */ + +Blockly.Msg.badges_explaination = "Eine Übersicht über alle erhaltenen Badges im Kontext Blockly for senseBox findest du " +Blockly.Msg.badges_ASSIGNE_BADGE_SUCCESS_01 = "Herzlichen Glückwunsch! Du hast den Badge " +Blockly.Msg.badges_ASSIGNE_BADGE_SUCCESS_02 = " erhalten." +/** + * Tutorials + */ + +Blockly.Msg.tutorials_assessment_task = "Aufgabe" +Blockly.Msg.tutorials_hardware_head = "Für die Umsetzung benötigst du folgende Hardware:" +Blockly.Msg.tutorials_hardware_moreInformation = "Weitere Informationen zur Hardware-Komponente findest du" +Blockly.Msg.tutorials_hardware_here = "hier"; +Blockly.Msg.tutorials_requirements = "Bevor du mit diesem Tutorial fortfährst solltest du folgende Tutorials erfolgreich abgeschlossen haben:" + + +/** + * Tutorial Builder + */ + +Blockly.Msg.builder_solution = "Lösung" +Blockly.Msg.builder_solution_submit = "Lösung einreichen" +Blockly.Msg.builder_example_submit = "Beispiel einreichen" +Blockly.Msg.builder_comment = "Anmerkung: Man kann den initialen Setup()- bzw. Endlosschleifen()-Block löschen. Zusätzlich ist es möglich u.a. nur einen beliebigen Block auszuwählen, ohne dass dieser als deaktiviert dargestellt wird." +Blockly.Msg.builder_hardware_order = "Beachte, dass die Reihenfolge des Auswählens maßgebend ist." +Blockly.Msg.builder_hardware_helper = "Wähle mindestens eine Hardware-Komponente aus." +Blockly.Msg.builder_requirements_head = "Voraussetzungen" +Blockly.Msg.builder_requirements_order = "Beachte, dass die Reihenfolge des Anhakens maßgebend ist." + +/** + * Login + */ + + +Blockly.Msg.login_head = "Anmelden" export const De = Blockly.Msg; diff --git a/src/components/Blockly/msg/en.js b/src/components/Blockly/msg/en.js index 696d68e..b895bac 100644 --- a/src/components/Blockly/msg/en.js +++ b/src/components/Blockly/msg/en.js @@ -782,4 +782,101 @@ Blockly.Msg.senseBox_mqtt_password = "Password"; Blockly.Msg.sensebox_mqtt_subscribe = "Subscribe to Feed" Blockly.Msg.senseBox_mqtt_publish = "Publish to Feed/Topic"; + +/** + * Add Translation for Blocks above + * --------------------------------------------------------------- + * Add Translation for the UI below + */ + + +/** + * Toolbox + */ +Blockly.Msg.toolbox_sensors = "Sensors"; +Blockly.Msg.toolbox_logic = "Logic"; +Blockly.Msg.toolbox_loops = "Loops"; +Blockly.Msg.toolbox_math = "Math"; +Blockly.Msg.toolbox_io = "Input/Output"; +Blockly.Msg.toolbox_time = "Time"; +Blockly.Msg.toolbox_functions = "Functions"; +Blockly.Msg.toolbox_variables = "Variables"; + + +/** + * Tooltips + * + */ + +Blockly.Msg.tooltip_compile_code = "Compile Code" +Blockly.Msg.tooltip_save_blocks = "Save Blocks"; +Blockly.Msg.tooltip_open_blocks = "Open Blocks"; +Blockly.Msg.tooltip_screenshot = "Download Screenshot"; +Blockly.Msg.tooltip_clear_workspace = "Reset Workspace"; +Blockly.Msg.tooltip_share_blocks = "Share Blocks"; +Blockly.Msg.tooltip_show_code = "Show Code"; +Blockly.Msg.tooltip_hide_code = "Hide Code" + +Blockly.Msg.tooltip_project_name = "Projectname" +/** + * Share Dialog + */ + +Blockly.Msg.sharedialog_headline = "Your Share-Link was created"; +Blockly.Msg.sharedialog_text = "Share your project with the following link"; + +/** + * Project rename Dialog + */ + +Blockly.Msg.renamedialog_headline = "Rename Project"; +Blockly.Msg.renamedialog_text = "Please enter a name for the project and confirm it by clicking on 'Confirm'." + +/** + * Compile Dialog + * + */ + +Blockly.Msg.compiledialog_headline = "Error" +Blockly.Msg.compiledialog_text = "While compiling an error occured. Please check your blocks and try again" + + + +/** + * Buttons + * + */ + +Blockly.Msg.button_cancel = "Cancel"; +Blockly.Msg.button_close = "Close"; +Blockly.Msg.button_accept = "Confirm"; +Blockly.Msg.button_compile = "Compile"; +Blockly.Msg.button_create_variableCreate = "Create Variable"; + + +/** + * + */ + +Blockly.Msg.filename = "Filename"; +Blockly.Msg.projectname = "Projectname"; + +/** + * Settings + */ +Blockly.Msg.settings_head = "Settings" +Blockly.Msg.settings_language = "Language" +Blockly.Msg.settings_language_text = "Selection of the language applies to the entire application. A distinction can be made between German and English." +Blockly.Msg.settings_language_de = "German" +Blockly.Msg.settings_language_en = "English" +Blockly.Msg.settings_renderer = "Renderer" +Blockly.Msg.settings_renderer_text = "The selected renderer determines the appearance of the blocks. A distinction can be made between 'Geras' and 'Zelos', whereby 'Zelos' is particularly suitable for a touch application." +Blockly.Msg.settings_statistics = "Statistics" +Blockly.Msg.settings_statistics_text = "The display of statistics on the usage of the blocks above the workspace can be shown or hidden." +Blockly.Msg.settings_statistics_on = "On" +Blockly.Msg.settings_statistics_off = "Off" + + + + export const En = Blockly.Msg; diff --git a/src/components/Blockly/toolbox/Toolbox.js b/src/components/Blockly/toolbox/Toolbox.js index 47fede7..cce1097 100644 --- a/src/components/Blockly/toolbox/Toolbox.js +++ b/src/components/Blockly/toolbox/Toolbox.js @@ -38,7 +38,7 @@ class Toolbox extends React.Component { render() { return ( - + @@ -301,7 +301,7 @@ class Toolbox extends React.Component { {/* */} - + @@ -310,7 +310,7 @@ class Toolbox extends React.Component { - + @@ -349,7 +349,7 @@ class Toolbox extends React.Component { - + @@ -369,7 +369,7 @@ class Toolbox extends React.Component { - + @@ -422,15 +422,15 @@ class Toolbox extends React.Component { - + - + - + diff --git a/src/components/Content.js b/src/components/Content.js new file mode 100644 index 0000000..9260421 --- /dev/null +++ b/src/components/Content.js @@ -0,0 +1,54 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; + +import * as Blockly from 'blockly/core'; +import { De } from './Blockly/msg/de'; +import { En } from './Blockly/msg/en'; + +import Navbar from './Navbar'; +import Footer from './Footer'; +import Routes from './Route/Routes'; +import Cookies from './Cookies'; + +class Content extends Component { + + componentDidMount() { + if (this.props.language === 'de_DE') { + Blockly.setLocale(De); + } else if (this.props.language === 'en_US') { + Blockly.setLocale(En); + } + } + + componentDidUpdate(props){ + if(props.language !== this.props.language){ + if (this.props.language === 'de_DE') { + Blockly.setLocale(De); + } else if (this.props.language === 'en_US') { + Blockly.setLocale(En); + } + } + } + + render() { + return ( +
+ + + +
+
+ ); + } +} + +Content.propTypes = { + language: PropTypes.string.isRequired +}; + +const mapStateToProps = state => ({ + language: state.general.language +}); + +export default connect(mapStateToProps, null)(Content); diff --git a/src/components/Home.js b/src/components/Home.js index 7c385ac..f5ec9cb 100644 --- a/src/components/Home.js +++ b/src/components/Home.js @@ -48,7 +48,6 @@ class Home extends Component { state = { codeOn: false, - stats: window.localStorage.getItem('stats'), snackbar: false, type: '', key: '', @@ -91,7 +90,7 @@ class Home extends Component { render() { return (
- {this.state.stats ? + {this.props.statistics ?
: null } @@ -136,11 +135,13 @@ class Home extends Component { Home.propTypes = { clearStats: PropTypes.func.isRequired, workspaceName: PropTypes.func.isRequired, - message: PropTypes.object.isRequired + message: PropTypes.object.isRequired, + statistics: PropTypes.bool.isRequired }; const mapStateToProps = state => ({ - message: state.message + message: state.message, + statistics: state.general.statistics }); diff --git a/src/components/Navbar.js b/src/components/Navbar.js index 2bc7b62..a3e6949 100644 --- a/src/components/Navbar.js +++ b/src/components/Navbar.js @@ -21,7 +21,7 @@ import ListItemIcon from '@material-ui/core/ListItemIcon'; import ListItemText from '@material-ui/core/ListItemText'; import LinearProgress from '@material-ui/core/LinearProgress'; -import { faBars, faChevronLeft, faLayerGroup, faSignInAlt, faSignOutAlt, faCertificate, faUserCircle, faIdCard, faEnvelope, faCog, faChalkboardTeacher, faFolderPlus, faTools, faLightbulb } from "@fortawesome/free-solid-svg-icons"; +import { faBars, faChevronLeft, faLayerGroup, faSignInAlt, faSignOutAlt, faCertificate, faUserCircle, faCog, faChalkboardTeacher, faTools, faLightbulb } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ @@ -101,46 +101,46 @@ class Navbar extends Component {
{[{ text: 'Tutorials', icon: faChalkboardTeacher, link: "/tutorial" }, - { text: 'Tutorial-Builder', icon: faTools, link: "/tutorial/builder", restriction: this.props.user && this.props.user.blocklyRole !== 'user' && this.props.isAuthenticated}, - { text: 'Galerie', icon: faLightbulb, link: "/gallery" }, - { text: 'Projekte', icon: faLayerGroup, link: "/project", restriction: this.props.isAuthenticated }].map((item, index) => { - if(item.restriction || Object.keys(item).filter(attribute => attribute === 'restriction').length === 0){ - return( - - - - - - - ); - } + { text: 'Tutorial-Builder', icon: faTools, link: "/tutorial/builder", restriction: this.props.user && this.props.user.blocklyRole !== 'user' && this.props.isAuthenticated }, + { text: 'Galerie', icon: faLightbulb, link: "/gallery" }, + { text: 'Projekte', icon: faLayerGroup, link: "/project", restriction: this.props.isAuthenticated }].map((item, index) => { + if (item.restriction || Object.keys(item).filter(attribute => attribute === 'restriction').length === 0) { + return ( + + + + + + + ); } + } )} {[{ text: 'Anmelden', icon: faSignInAlt, link: '/user/login', restriction: !this.props.isAuthenticated }, - { text: 'Konto', icon: faUserCircle, link: '/user', restriction: this.props.isAuthenticated }, - { text: 'MyBadges', icon: faCertificate, link: '/user/badge', restriction: this.props.isAuthenticated }, - { text: 'Abmelden', icon: faSignOutAlt, function: this.props.logout, restriction: this.props.isAuthenticated }, - { text: 'Einstellungen', icon: faCog, link: "/settings" }].map((item, index) => { - if(item.restriction || Object.keys(item).filter(attribute => attribute === 'restriction').length === 0){ - return( - - {item.function(); this.toggleDrawer();} : this.toggleDrawer}> - - - - - ); - } + { text: 'Konto', icon: faUserCircle, link: '/user', restriction: this.props.isAuthenticated }, + { text: 'MyBadges', icon: faCertificate, link: '/user/badge', restriction: this.props.isAuthenticated }, + { text: 'Abmelden', icon: faSignOutAlt, function: this.props.logout, restriction: this.props.isAuthenticated }, + { text: 'Einstellungen', icon: faCog, link: "/settings" }].map((item, index) => { + if (item.restriction || Object.keys(item).filter(attribute => attribute === 'restriction').length === 0) { + return ( + + { item.function(); this.toggleDrawer(); } : this.toggleDrawer}> + + + + + ); } + } )} {this.props.tutorialIsLoading || this.props.projectIsLoading ? - - : null} + + : null} ); } diff --git a/src/components/NotFound.js b/src/components/NotFound.js index 85a9c6f..01b03f7 100644 --- a/src/components/NotFound.js +++ b/src/components/NotFound.js @@ -6,31 +6,39 @@ import { withRouter } from 'react-router-dom'; import Button from '@material-ui/core/Button'; import Typography from '@material-ui/core/Typography'; +import * as Blockly from 'blockly' class NotFound extends Component { + + componentDidMount(){ + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } + render() { return (
- - Die von Ihnen angeforderte Seite kann nicht gefunden werden. - Die gesuchte Seite wurde möglicherweise entfernt, ihr Name wurde geändert oder sie ist vorübergehend nicht verfügbar. + + {Blockly.Msg.notfound_head} + {Blockly.Msg.notfound_text} {this.props.button ? - : + : }
diff --git a/src/components/Project/Project.js b/src/components/Project/Project.js index 7b16310..fa2353c 100644 --- a/src/components/Project/Project.js +++ b/src/components/Project/Project.js @@ -6,7 +6,6 @@ import { getProject, resetProject } from '../../actions/projectActions'; import { clearMessages, returnErrors } from '../../actions/messageActions'; import { withRouter } from 'react-router-dom'; -import { createNameId } from 'mnemonic-id'; import Home from '../Home'; import Breadcrumbs from '../Breadcrumbs'; @@ -23,16 +22,16 @@ class Project extends Component { } componentDidUpdate(props) { - if(props.location.pathname !== this.props.location.pathname || - props.match.params[`${this.props.type}Id`] !== this.props.match.params[`${this.props.type}Id`]){ - if(this.props.message.msg){ + if (props.location.pathname !== this.props.location.pathname || + props.match.params[`${this.props.type}Id`] !== this.props.match.params[`${this.props.type}Id`]) { + if (this.props.message.msg) { this.props.clearMessages(); } this.getProject(); } - if(this.props.message !== props.message){ - if(this.props.message.id === 'PROJECT_EMPTY' || this.props.message.id === 'GET_PROJECT_FAIL'){ - if(this.props.type!=='share'){ + if (this.props.message !== props.message) { + if (this.props.message.id === 'PROJECT_EMPTY' || this.props.message.id === 'GET_PROJECT_FAIL') { + if (this.props.type !== 'share') { this.props.returnErrors('', 404, 'GET_PROJECT_FAIL'); this.props.history.push(`/${this.props.type}`); } else { @@ -40,10 +39,10 @@ class Project extends Component { this.props.returnErrors('', 404, 'GET_SHARE_FAIL'); } } - else if(this.props.message.id === 'GET_PROJECT_SUCCESS'){ + else if (this.props.message.id === 'GET_PROJECT_SUCCESS') { this.props.workspaceName(this.props.project.title); } - else if(this.props.message.id === 'PROJECT_DELETE_SUCCESS' || this.props.message.id === 'GALLERY_DELETE_SUCCESS'){ + else if (this.props.message.id === 'PROJECT_DELETE_SUCCESS' || this.props.message.id === 'GALLERY_DELETE_SUCCESS') { this.props.history.push(`/${this.props.type}`); } } @@ -55,8 +54,8 @@ class Project extends Component { } getProject = () => { - var id = this.props.location.pathname.replace(/\/[a-z]{1,}\//,''); - var param = this.props.location.pathname.replace(`/${id}`,'').replace('/',''); + var id = this.props.location.pathname.replace(/\/[a-z]{1,}\//, ''); + var param = this.props.location.pathname.replace(`/${id}`, '').replace('/', ''); console.log('param', param); console.log(id); this.props.getProject(param, id); @@ -69,13 +68,13 @@ class Project extends Component { - : this.props.project ? -
- {this.props.type !== 'share' ? - - : null} - -
: null + : this.props.project ? +
+ {this.props.type !== 'share' ? + + : null} + +
: null ); }; } diff --git a/src/components/Project/ProjectHome.js b/src/components/Project/ProjectHome.js index 06c0c2b..c7a8d8c 100644 --- a/src/components/Project/ProjectHome.js +++ b/src/components/Project/ProjectHome.js @@ -41,31 +41,31 @@ class ProjectHome extends Component { } componentDidMount() { - var type = this.props.location.pathname.replace('/',''); + var type = this.props.location.pathname.replace('/', ''); this.props.getProjects(type); - if(this.props.message){ - if(this.props.message.id === 'PROJECT_DELETE_SUCCESS'){ + if (this.props.message) { + if (this.props.message.id === 'PROJECT_DELETE_SUCCESS') { this.setState({ snackbar: true, key: Date.now(), message: `Dein Projekt wurde erfolgreich gelöscht.`, type: 'success' }); } - else if(this.props.message.id === 'GALLERY_DELETE_SUCCESS'){ + else if (this.props.message.id === 'GALLERY_DELETE_SUCCESS') { this.setState({ snackbar: true, key: Date.now(), message: `Dein Galerie-Projekt wurde erfolgreich gelöscht.`, type: 'success' }); } - else if(this.props.message.id === 'GET_PROJECT_FAIL'){ - this.setState({ snackbar: true, key: Date.now(), message: `Dein angefragtes ${type === 'gallery' ? 'Galerie-':''}Projekt konnte nicht gefunden werden.`, type: 'error' }); + else if (this.props.message.id === 'GET_PROJECT_FAIL') { + this.setState({ snackbar: true, key: Date.now(), message: `Dein angefragtes ${type === 'gallery' ? 'Galerie-' : ''}Projekt konnte nicht gefunden werden.`, type: 'error' }); } } } componentDidUpdate(props) { - if(props.location.pathname !== this.props.location.pathname){ - this.setState({snackbar: false}); - this.props.getProjects(this.props.location.pathname.replace('/','')); + if (props.location.pathname !== this.props.location.pathname) { + this.setState({ snackbar: false }); + this.props.getProjects(this.props.location.pathname.replace('/', '')); } - if(props.message !== this.props.message){ - if(this.props.message.id === 'PROJECT_DELETE_SUCCESS'){ + if (props.message !== this.props.message) { + if (this.props.message.id === 'PROJECT_DELETE_SUCCESS') { this.setState({ snackbar: true, key: Date.now(), message: `Dein Projekt wurde erfolgreich gelöscht.`, type: 'success' }); } - else if(this.props.message.id === 'GALLERY_DELETE_SUCCESS'){ + else if (this.props.message.id === 'GALLERY_DELETE_SUCCESS') { this.setState({ snackbar: true, key: Date.now(), message: `Dein Galerie-Projekt wurde erfolgreich gelöscht.`, type: 'success' }); } } @@ -87,7 +87,7 @@ class ProjectHome extends Component { - : + :
{this.props.projects.length > 0 ? @@ -96,37 +96,37 @@ class ProjectHome extends Component { -

{project.title}

- +

{project.title}

+ - {project.description} + {project.description} {this.props.user && this.props.user.email === project.creator ?
- -
+ +
- : null} + : null} ) })} - :
- Es sind aktuell keine Projekte vorhanden. - {this.props.location.pathname.replace('/','') === 'project' ? + :
+ Es sind aktuell keine Projekte vorhanden. + {this.props.location.pathname.replace('/', '') === 'project' ? Erstelle jetzt dein eigenes Projekt oder lasse dich von Projektbeispielen in der Galerie inspirieren. - : null} + : null}
}
diff --git a/src/components/Settings/LanguageSelector.js b/src/components/Settings/LanguageSelector.js index dea7465..f069b1b 100644 --- a/src/components/Settings/LanguageSelector.js +++ b/src/components/Settings/LanguageSelector.js @@ -1,43 +1,58 @@ -import React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { setLanguage } from '../../actions/generalActions'; + +import * as Blockly from 'blockly/core'; + import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import FormControl from '@material-ui/core/FormControl'; import Select from '@material-ui/core/Select'; +import Typography from '@material-ui/core/Typography'; +import FormHelperText from '@material-ui/core/FormHelperText'; -const useStyles = makeStyles((theme) => ({ - formControl: { - margin: theme.spacing(1), - minWidth: 120, - }, - selectEmpty: { - marginTop: theme.spacing(2), - }, -})); +class LanguageSelector extends Component { -export default function LanguageSelector() { - const classes = useStyles(); - const [lang, setLang] = React.useState(window.localStorage.getItem('locale')); + componentDidMount(){ + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } - const handleChange = (event) => { - setLang(event.target.value); - window.localStorage.setItem('locale', event.target.value); - }; + handleChange = (event) => { + this.props.setLanguage(event.target.value); + } - return ( -
- - Sprache - - -
+ render(){ + return( +
+ {Blockly.Msg.settings_language} + {Blockly.Msg.settings_language_text} + + {Blockly.Msg.settings_language} + + +
); + } } + +LanguageSelector.propTypes = { + setLanguage: PropTypes.func.isRequired, + language: PropTypes.string.isRequired +}; + +const mapStateToProps = state => ({ + language: state.general.language +}); + +export default connect(mapStateToProps, { setLanguage })(LanguageSelector); diff --git a/src/components/Settings/RenderSelector.js b/src/components/Settings/RenderSelector.js index 5cf7a9f..7359283 100644 --- a/src/components/Settings/RenderSelector.js +++ b/src/components/Settings/RenderSelector.js @@ -1,45 +1,57 @@ -import React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { setRenderer } from '../../actions/generalActions'; + +import * as Blockly from 'blockly/core' + import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import FormControl from '@material-ui/core/FormControl'; import Select from '@material-ui/core/Select'; +import Typography from '@material-ui/core/Typography'; +import FormHelperText from '@material-ui/core/FormHelperText'; -const useStyles = makeStyles((theme) => ({ - formControl: { - margin: theme.spacing(1), - minWidth: 400, - }, - selectEmpty: { - marginTop: theme.spacing(2), - }, -})); -export default function RenderSelector() { - const classes = useStyles(); - const [renderer, setRenderer] = React.useState(window.localStorage.getItem('renderer')); +class RenderSelector extends Component { - const handleChange = (event) => { - setRenderer(event.target.value); - window.localStorage.setItem('renderer', event.target.value); - }; + componentDidMount(){ + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } + render(){ return ( -
- - Renderer - - -

Der Renderer bestimmt das aussehen der Blöcke

-
+
+ {Blockly.Msg.settings_renderer} + {Blockly.Msg.settings_renderer_text} + + {Blockly.Msg.settings_renderer} + + +
); + } } + +RenderSelector.propTypes = { + setRenderer: PropTypes.func.isRequired, + language: PropTypes.string.isRequired, + renderer: PropTypes.string.isRequired +}; + +const mapStateToProps = state => ({ + renderer: state.general.renderer, + language: state.general.language +}); + +export default connect(mapStateToProps, { setRenderer })(RenderSelector); diff --git a/src/components/Settings/Settings.js b/src/components/Settings/Settings.js index cbbedc9..24b3bfa 100644 --- a/src/components/Settings/Settings.js +++ b/src/components/Settings/Settings.js @@ -1,32 +1,65 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; + import { withRouter } from 'react-router-dom'; -import Button from '@material-ui/core/Button'; -import Typography from '@material-ui/core/Typography'; +import * as Blockly from 'blockly/core'; + +import Breadcrumbs from '../Breadcrumbs'; import LanguageSelector from './LanguageSelector'; import RenderSelector from './RenderSelector'; import StatsSelector from './StatsSelector'; +import Button from '@material-ui/core/Button'; +import Paper from '@material-ui/core/Paper'; class Settings extends Component { - render() { - return ( -
- Einstellungen - - - - -
- ); - }; + + componentDidMount(){ + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } + + render() { + return ( +
+ + +

{Blockly.Msg.settings_head}

+ + + + + + + + + + + + +
+ ); + }; } -export default withRouter(Settings); +Settings.propTypes = { + language: PropTypes.string.isRequired, + pageVisits: PropTypes.number.isRequired +}; + +const mapStateToProps = state => ({ + language: state.general.language, + pageVisits: state.general.pageVisits +}); + +export default connect(mapStateToProps, null)(withRouter(Settings)); diff --git a/src/components/Settings/StatsSelector.js b/src/components/Settings/StatsSelector.js index 8c1322d..b0b3cfe 100644 --- a/src/components/Settings/StatsSelector.js +++ b/src/components/Settings/StatsSelector.js @@ -1,44 +1,56 @@ -import React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { connect } from 'react-redux'; +import { setStatistics } from '../../actions/generalActions'; + +import * as Blockly from 'blockly/core' + import InputLabel from '@material-ui/core/InputLabel'; import MenuItem from '@material-ui/core/MenuItem'; import FormControl from '@material-ui/core/FormControl'; import Select from '@material-ui/core/Select'; +import Typography from '@material-ui/core/Typography'; +import FormHelperText from '@material-ui/core/FormHelperText'; -const useStyles = makeStyles((theme) => ({ - formControl: { - margin: theme.spacing(1), - minWidth: 400, - }, - selectEmpty: { - marginTop: theme.spacing(2), - }, -})); +class StatsSelector extends Component { -export default function StatsSelector() { - const classes = useStyles(); - const [stats, setStats] = React.useState(window.localStorage.getItem('stats')); - - const handleChange = (event) => { - setStats(event.target.value); - window.localStorage.setItem('stats', event.target.value); - }; + componentDidMount(){ + // Ensure that Blockly.setLocale is adopted in the component. + // Otherwise, the text will not be displayed until the next update of the component. + this.forceUpdate(); + } + render(){ return ( -
- - Statistiken - - -

Schaltet die Statistiken Oberhalb der Arbeitsfläche ein bzw. aus

-
+
+ {Blockly.Msg.settings_statistics} + {Blockly.Msg.settings_statistics_text} + + {Blockly.Msg.settings_statistics} + + +
); + } } + +StatsSelector.propTypes = { + setStatistics: PropTypes.func.isRequired, + language: PropTypes.string.isRequired, + statistics: PropTypes.bool.isRequired +}; + +const mapStateToProps = state => ({ + statistics: state.general.statistics, + language: state.general.language +}); + +export default connect(mapStateToProps, { setStatistics })(StatsSelector); diff --git a/src/components/Tutorial/Assessment.js b/src/components/Tutorial/Assessment.js index 75e180d..c869cc5 100644 --- a/src/components/Tutorial/Assessment.js +++ b/src/components/Tutorial/Assessment.js @@ -11,6 +11,7 @@ import withWidth, { isWidthDown } from '@material-ui/core/withWidth'; import Grid from '@material-ui/core/Grid'; import Card from '@material-ui/core/Card'; import Typography from '@material-ui/core/Typography'; +import * as Blockly from 'blockly' class Assessment extends Component { @@ -45,7 +46,7 @@ class Assessment extends Component { - Arbeitsauftrag + {Blockly.Msg.tutorials_assessment_task} {currentTask.text}
diff --git a/src/components/Tutorial/Badge.js b/src/components/Tutorial/Badge.js index 97103fa..2727fa5 100644 --- a/src/components/Tutorial/Badge.js +++ b/src/components/Tutorial/Badge.js @@ -11,6 +11,7 @@ import { withStyles } from '@material-ui/core/styles'; import Paper from '@material-ui/core/Paper'; import Typography from '@material-ui/core/Typography'; import Avatar from '@material-ui/core/Avatar'; +import * as Blockly from 'blockly'; const styles = (theme) => ({ link: { @@ -32,22 +33,22 @@ class Badge extends Component { content: '' }; - componentDidUpdate(props){ - if(this.props.message.id === 'TUTORIAL_CHECK_SUCCESS'){ - if(this.props.tutorial.badge){ + componentDidUpdate(props) { + if (this.props.message.id === 'TUTORIAL_CHECK_SUCCESS') { + if (this.props.tutorial.badge) { // is connected to MyBadges? - if(this.props.isAuthenticated && this.props.user && this.props.user.badge){ - if(this.props.user.badges && !this.props.user.badges.includes(this.props.tutorial.badge)){ - if(this.isSuccess()){ + if (this.props.isAuthenticated && this.props.user && this.props.user.badge) { + if (this.props.user.badges && !this.props.user.badges.includes(this.props.tutorial.badge)) { + if (this.isSuccess()) { this.props.assigneBadge(this.props.tutorial.badge); } } } } } - if(props.message !== this.props.message){ - if(this.props.message.id === 'ASSIGNE_BADGE_SUCCESS'){ - this.setState({title: `Badge: ${this.props.message.msg.name}`, content: `Herzlichen Glückwunsch! Du hast den Badge ${this.props.message.msg.name} erhalten.`, open: true}); + if (props.message !== this.props.message) { + if (this.props.message.id === 'ASSIGNE_BADGE_SUCCESS') { + this.setState({ title: `Badge: ${this.props.message.msg.name}`, content: `${Blockly.Msg.badges_ASSIGNE_BADGE_SUCCESS_01} ${this.props.message.msg.name} ${Blockly.Msg.badges_ASSIGNE_BADGE_SUCCESS_02}`, open: true }); } } } @@ -57,7 +58,7 @@ class Badge extends Component { var status = this.props.status.filter(status => status._id === tutorialId)[0]; var tasks = status.tasks; var success = tasks.filter(task => task.type === 'success').length / tasks.length; - if(success===1){ + if (success === 1) { return true; } return false; @@ -74,21 +75,21 @@ class Badge extends Component { open={this.state.open} title={this.state.title} content={this.state.content} - onClose={() => {this.toggleDialog();}} - onClick={() => {this.toggleDialog();}} - button={'Schließen'} + onClose={() => { this.toggleDialog(); }} + onClick={() => { this.toggleDialog(); }} + button={Blockly.Msg.button_close} >
- + {this.props.message.msg.image && this.props.message.msg.image.path ? - - : } - -
{this.props.message.msg.name}
+ + : } + +
{this.props.message.msg.name}
- - Eine Übersicht über alle erhaltenen Badges im Kontext Blockly for senseBox findest du hier. + + {Blockly.Msg.badges_explaination}{Blockly.Msg.labels_here}.
diff --git a/src/components/Tutorial/Builder/BlocklyExample.js b/src/components/Tutorial/Builder/BlocklyExample.js index 01f52f4..75dc222 100644 --- a/src/components/Tutorial/Builder/BlocklyExample.js +++ b/src/components/Tutorial/Builder/BlocklyExample.js @@ -29,7 +29,7 @@ const styles = (theme) => ({ marginTop: '5px', height: '40px', backgroundColor: theme.palette.error.dark, - '&:hover':{ + '&:hover': { backgroundColor: theme.palette.error.dark } } @@ -37,16 +37,16 @@ const styles = (theme) => ({ class BlocklyExample extends Component { - constructor(props){ + constructor(props) { super(props); - this.state={ + this.state = { checked: props.task ? props.task : props.value ? true : false, input: null, disabled: false }; } - componentDidMount(){ + componentDidMount() { moment.updateLocale('de', localization); this.isError(); // if(this.props.task){ @@ -54,42 +54,42 @@ class BlocklyExample extends Component { // } } - componentDidUpdate(props, state){ - if(props.task !== this.props.task || props.value !== this.props.value){ - this.setState({checked: this.props.task ? this.props.task : this.props.value ? true : false}, + componentDidUpdate(props, state) { + if (props.task !== this.props.task || props.value !== this.props.value) { + this.setState({ checked: this.props.task ? this.props.task : this.props.value ? true : false }, () => this.isError() ); } - if(state.checked !== this.state.checked && this.state.checked){ + if (state.checked !== this.state.checked && this.state.checked) { this.isError(); } - if(props.xml !== this.props.xml){ + if (props.xml !== this.props.xml) { // check if there is at least one block, otherwise the workspace cannot be submitted var workspace = Blockly.getMainWorkspace(); var areBlocks = workspace.getAllBlocks().length > 0; - this.setState({disabled: !areBlocks}); + this.setState({ disabled: !areBlocks }); } } isError = () => { - if(this.state.checked){ + if (this.state.checked) { var xml = this.props.value; // check if value is valid xml; - try{ + try { Blockly.Xml.textToDom(xml); this.props.deleteError(this.props.index, 'xml'); } - catch(err){ + catch (err) { xml = initialXml; // not valid xml, throw error in redux store this.props.setError(this.props.index, 'xml'); } - if(!this.props.task){ + if (!this.props.task) { // instruction can also display only one block, which does not necessarily // have to be the initial block xml = xml.replace('deletable="false"', 'deletable="true"'); } - this.setState({xml: xml}); + this.setState({ xml: xml }); } else { this.props.deleteError(this.props.index, 'xml'); @@ -98,8 +98,8 @@ class BlocklyExample extends Component { onChange = (value) => { var oldValue = this.state.checked; - this.setState({checked: value}); - if(oldValue !== value && !value){ + this.setState({ checked: value }); + if (oldValue !== value && !value) { this.props.deleteError(this.props.index, 'xml'); this.props.deleteProperty(this.props.index, 'xml'); } @@ -108,12 +108,12 @@ class BlocklyExample extends Component { setXml = () => { var xml = this.props.xml; this.props.changeContent(xml, this.props.index, 'xml'); - this.setState({input: moment(Date.now()).format('LTS')}); + this.setState({ input: moment(Date.now()).format('LTS') }); } render() { return ( -
+
{!this.props.task ? } /> - : Musterlösung} + : {Blockly.Msg.builder_solution}} {this.state.checked ? !this.props.value || this.props.error ? - {`Reiche deine Blöcke ein, indem du auf den '${this.props.task ? 'Musterlösung einreichen' : 'Beispiel einreichen'}'-Button klickst.`} - : this.state.input ? Die letzte Einreichung erfolgte um {this.state.input} Uhr. : null - : null} + {`Reiche deine Blöcke ein, indem du auf den '${this.props.task ? Blockly.Msg.builder_solution_submit : Blockly.Msg.builder_example_submit}'-Button klickst.`} + : this.state.input ? Die letzte Einreichung erfolgte um {this.state.input} Uhr. : null + : null} {this.state.checked && !this.props.task ? - Anmerkung: Man kann den initialen Setup()- bzw. Endlosschleifen()-Block löschen. Zusätzlich ist es möglich u.a. nur einen beliebigen Block auszuwählen, ohne dass dieser als deaktiviert dargestellt wird. - : null} + {Blockly.Msg.builder_comment} + : null} {/* ensure that the correct xml-file is displayed in the workspace */} - {this.state.checked && this.state.xml? (() => { - return( -
+ {this.state.checked && this.state.xml ? (() => { + return ( +
- )})() - : null} + ) + })() + : null}
); }; @@ -179,4 +180,4 @@ const mapStateToProps = state => ({ }); -export default connect(mapStateToProps, { changeContent, deleteProperty, setError, deleteError })(withStyles(styles, {withTheme: true})(BlocklyExample)); +export default connect(mapStateToProps, { changeContent, deleteProperty, setError, deleteError })(withStyles(styles, { withTheme: true })(BlocklyExample)); diff --git a/src/components/Tutorial/Builder/Builder.js b/src/components/Tutorial/Builder/Builder.js index bd4e8a0..40595cc 100644 --- a/src/components/Tutorial/Builder/Builder.js +++ b/src/components/Tutorial/Builder/Builder.js @@ -8,8 +8,6 @@ import { clearMessages } from '../../../actions/messageActions'; import axios from 'axios'; import { withRouter } from 'react-router-dom'; -import { saveAs } from 'file-saver'; -import { detectWhitespacesAndReturnReadableResult } from '../../../helpers/whitespace'; import Breadcrumbs from '../../Breadcrumbs'; import Badge from './Badge'; @@ -44,7 +42,7 @@ const styles = (theme) => ({ marginTop: '5px', height: '40px', backgroundColor: theme.palette.error.dark, - '&:hover':{ + '&:hover': { backgroundColor: theme.palette.error.dark } } @@ -87,11 +85,11 @@ class Builder extends Component { // alert(this.props.message.msg); this.props.clearMessages(); } - else if(this.props.message.id === 'TUTORIAL_DELETE_SUCCESS'){ + else if (this.props.message.id === 'TUTORIAL_DELETE_SUCCESS') { this.onChange('new'); this.setState({ snackbar: true, key: Date.now(), message: `Das Tutorial wurde erfolgreich gelöscht.`, type: 'success' }); } - else if(this.props.message.id === 'TUTORIAL_DELETE_FAIL'){ + else if (this.props.message.id === 'TUTORIAL_DELETE_FAIL') { this.setState({ snackbar: true, key: Date.now(), message: `Fehler beim Löschen des Tutorials. Versuche es noch einmal.`, type: 'error' }); } } @@ -100,7 +98,7 @@ class Builder extends Component { componentWillUnmount() { this.resetFull(); this.props.resetTutorial(); - if(this.props.message.msg){ + if (this.props.message.msg) { this.props.clearMessages(); } } @@ -153,12 +151,12 @@ class Builder extends Component { onChange = (value) => { this.props.resetTutorialBuilder(); this.props.tutorialId(''); - this.setState({tutorial: value}); + this.setState({ tutorial: value }); } onChangeId = (value) => { this.props.tutorialId(value); - if(this.state.tutorial === 'change'){ + if (this.state.tutorial === 'change') { this.props.progress(true); var tutorial = this.props.tutorials.filter(tutorial => tutorial._id === value)[0]; this.props.readJSON(tutorial); @@ -201,8 +199,8 @@ class Builder extends Component { newTutorial.append(`steps[${i}][type]`, step.type); newTutorial.append(`steps[${i}][headline]`, step.headline); newTutorial.append(`steps[${i}][text]`, step.text); - if(i === 0 && step.type === 'instruction'){ - if(step.requirements){ // optional + if (i === 0 && step.type === 'instruction') { + if (step.requirements) { // optional step.requirements.forEach((requirement, j) => { newTutorial.append(`steps[${i}][requirements][${j}]`, requirement); }); @@ -211,14 +209,14 @@ class Builder extends Component { newTutorial.append(`steps[${i}][hardware][${j}]`, hardware); }); } - if(step.xml){ // optional + if (step.xml) { // optional newTutorial.append(`steps[${i}][xml]`, step.xml); } - if(step.media){ // optional - if(step.media.youtube){ + if (step.media) { // optional + if (step.media.youtube) { newTutorial.append(`steps[${i}][media][youtube]`, step.media.youtube); } - if(step.media.picture){ + if (step.media.picture) { newTutorial.append(`steps[${i}][media][picture]`, step.media.picture); } } @@ -282,30 +280,30 @@ class Builder extends Component {

Tutorial-Builder

this.onChange(e.target.value)}> - } label="neues Tutorial erstellen" labelPlacement="end" /> {filteredTutorials.length > 0 ? -
- } - label="bestehendes Tutorial ändern" - labelPlacement="end" - /> - } - label="bestehendes Tutorial löschen" - labelPlacement="end" - /> -
- : null} +
+ } + label="bestehendes Tutorial ändern" + labelPlacement="end" + /> + } + label="bestehendes Tutorial löschen" + labelPlacement="end" + /> +
+ : null}
@@ -325,7 +323,7 @@ class Builder extends Component {
- : + : Tutorial