Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion src/blocks/mrc_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { getAllowedTypesForSetCheck, getClassData, getModuleData, getSubclassNames } from './utils/python';
import * as toolboxItems from '../toolbox/items';
import * as commonStorage from '../storage/common_storage';
import * as storageNames from '../storage/names';
import { createPortShadow } from './mrc_port';
import { createNumberShadowValue } from './utils/value';
import { ClassData, FunctionData } from './utils/python_json_types';
Expand Down Expand Up @@ -216,7 +217,7 @@ export function getAllPossibleComponents(moduleType: string): toolboxItems.Conte

const componentName = (
'my_' +
commonStorage.pascalCaseToSnakeCase(
storageNames.pascalCaseToSnakeCase(
componentType.substring(componentType.lastIndexOf('.') + 1)));

classData.staticMethods.forEach(staticFunctionData => {
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/mrc_mechanism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ExtendedPythonGenerator } from '../editor/extended_python_generator';
import { getAllowedTypesForSetCheck } from './utils/python';
import * as toolboxItems from '../toolbox/items';
import * as commonStorage from '../storage/common_storage';
import * as storageNames from '../storage/names';
import * as value from './utils/value';
import { renameMethodCallers } from './mrc_call_python_function'

Expand Down Expand Up @@ -186,7 +187,7 @@ const MECHANISM = {
if (this.getFieldValue(FIELD_TYPE) !== foundMechanism.className) {
this.setFieldValue(foundMechanism.className, FIELD_TYPE);
}
const importModule = commonStorage.pascalCaseToSnakeCase(foundMechanism.className);
const importModule = storageNames.pascalCaseToSnakeCase(foundMechanism.className);
if (this.mrcImportModule !== importModule) {
this.mrcImportModule = importModule;
}
Expand Down Expand Up @@ -246,7 +247,7 @@ export const pythonFromBlock = function (

export function createMechanismBlock(
mechanism: commonStorage.Mechanism, components: commonStorage.Component[]): toolboxItems.Block {
const snakeCaseName = commonStorage.pascalCaseToSnakeCase(mechanism.className);
const snakeCaseName = storageNames.pascalCaseToSnakeCase(mechanism.className);
const mechanismName = 'my_' + snakeCaseName;
const extraState: MechanismExtraState = {
importModule: snakeCaseName,
Expand Down
3 changes: 2 additions & 1 deletion src/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as Blockly from 'blockly/core';
import { extendedPythonGenerator } from './extended_python_generator';
import { GeneratorContext } from './generator_context';
import * as commonStorage from '../storage/common_storage';
import * as storageNames from '../storage/names';
import * as eventHandler from '../blocks/mrc_event_handler';
import * as classMethodDef from '../blocks/mrc_class_method_def';
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
Expand Down Expand Up @@ -382,7 +383,7 @@ export class Editor {
public getMechanism(mechanismInRobot: commonStorage.MechanismInRobot): commonStorage.Mechanism | null {
if (this.currentProject) {
for (const mechanism of this.currentProject.mechanisms) {
const fullClassName = commonStorage.pascalCaseToSnakeCase(mechanism.className) + '.' + mechanism.className;
const fullClassName = storageNames.pascalCaseToSnakeCase(mechanism.className) + '.' + mechanism.className;
if (fullClassName === mechanismInRobot.className) {
return mechanism;
}
Expand Down
7 changes: 4 additions & 3 deletions src/reactComponents/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as Antd from 'antd';
import * as React from 'react';
import { RcFile, UploadRequestOption } from 'rc-upload/lib/interface';
import * as commonStorage from '../storage/common_storage';
import * as storageNames from '../storage/names';
import * as createPythonFiles from '../storage/create_python_files';
import * as I18Next from 'react-i18next';
import {TabType } from '../types/TabType';
Expand Down Expand Up @@ -335,7 +336,7 @@ export function Component(props: MenuProps): React.JSX.Element {

try {
const blobUrl = await props.storage.downloadProject(props.project.projectName);
const filename = props.project.projectName + commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION;
const filename = props.project.projectName + storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION;

// Create a temporary link to download the file
const link = document.createElement('a');
Expand All @@ -361,9 +362,9 @@ export function Component(props: MenuProps): React.JSX.Element {
}

const uploadProps: Antd.UploadProps = {
accept: commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION,
accept: storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION,
beforeUpload: (file) => {
const isBlocks = file.name.endsWith(commonStorage.UPLOAD_DOWNLOAD_FILE_EXTENSION)
const isBlocks = file.name.endsWith(storageNames.UPLOAD_DOWNLOAD_FILE_EXTENSION)
if (!isBlocks) {
// TODO: i18n
props.setAlertErrorMessage(file.name + ' is not a blocks file');
Expand Down
3 changes: 2 additions & 1 deletion src/reactComponents/ProjectNameComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as Antd from 'antd';
import * as I18Next from 'react-i18next';
import * as React from 'react';
import * as commonStorage from '../storage/common_storage';
import * as storageNames from '../storage/names';

/** Props for the ProjectNameComponent. */
interface ProjectNameComponentProps {
Expand Down Expand Up @@ -63,7 +64,7 @@ export default function ProjectNameComponent(props: ProjectNameComponentProps):
return;
}

if (!commonStorage.isValidClassName(newProjectName)) {
if (!storageNames.isValidClassName(newProjectName)) {
showError(newProjectName + INVALID_NAME_MESSAGE_SUFFIX);
return;
}
Expand Down
29 changes: 15 additions & 14 deletions src/storage/client_side_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import * as commonStorage from './common_storage';
import * as names from './names';

// Functions for saving blocks modules to client side storage.

Expand Down Expand Up @@ -148,8 +149,8 @@ class ClientSideStorage implements commonStorage.Storage {
const module: commonStorage.Module = {
modulePath: path,
moduleType: moduleType,
projectName: commonStorage.getProjectName(path),
className: commonStorage.getClassName(path),
projectName: names.getProjectName(path),
className: names.getClassName(path),
dateModifiedMillis: value.dateModifiedMillis,
}
if (moduleType === commonStorage.MODULE_TYPE_ROBOT) {
Expand Down Expand Up @@ -243,8 +244,8 @@ class ClientSideStorage implements commonStorage.Storage {
}

async createProject(projectName: string, robotContent: string, opmodeContent : string): Promise<void> {
const modulePath = commonStorage.makeRobotPath(projectName);
const opmodePath = commonStorage.makeModulePath(projectName, commonStorage.CLASS_NAME_TELEOP);
const modulePath = names.makeRobotPath(projectName);
const opmodePath = names.makeModulePath(projectName, names.CLASS_NAME_TELEOP);

await this._saveModule(commonStorage.MODULE_TYPE_ROBOT, modulePath, robotContent);
await this._saveModule(commonStorage.MODULE_TYPE_OPMODE, opmodePath, opmodeContent);
Expand Down Expand Up @@ -340,13 +341,13 @@ class ClientSideStorage implements commonStorage.Storage {
const value = cursor.value;
const path = value.path;
const moduleType = value.type;
if (commonStorage.getProjectName(path) === oldProjectName) {
if (names.getProjectName(path) === oldProjectName) {
let newPath;
if (moduleType === commonStorage.MODULE_TYPE_ROBOT) {
newPath = commonStorage.makeRobotPath(newProjectName);
newPath = names.makeRobotPath(newProjectName);
} else {
const className = commonStorage.getClassName(path);
newPath = commonStorage.makeModulePath(newProjectName, className);
const className = names.getClassName(path);
newPath = names.makeModulePath(newProjectName, className);
}
oldToNewModulePaths[path] = newPath;
}
Expand Down Expand Up @@ -433,8 +434,8 @@ class ClientSideStorage implements commonStorage.Storage {
reject(new Error('IndexedDB transaction aborted.'));
};
const modulesObjectStore = transaction.objectStore(MODULES_STORE_NAME);
const oldModulePath = commonStorage.makeModulePath(projectName, oldClassName);
const newModulePath = commonStorage.makeModulePath(projectName, newClassName);
const oldModulePath = names.makeModulePath(projectName, oldClassName);
const newModulePath = names.makeModulePath(projectName, newClassName);
const getRequest = modulesObjectStore.get(oldModulePath);
getRequest.onerror = () => {
console.log('IndexedDB get request failed. getRequest.error is...');
Expand Down Expand Up @@ -496,7 +497,7 @@ class ClientSideStorage implements commonStorage.Storage {
if (cursor) {
const value = cursor.value;
const path = value.path;
if (commonStorage.getProjectName(path) === projectName) {
if (names.getProjectName(path) === projectName) {
modulePaths.push(path);
}
cursor.continue();
Expand Down Expand Up @@ -559,8 +560,8 @@ class ClientSideStorage implements commonStorage.Storage {
const cursor = openCursorRequest.result;
if (cursor) {
const value = cursor.value;
if (commonStorage.getProjectName(value.path) === projectName) {
const className = commonStorage.getClassName(value.path);
if (names.getProjectName(value.path) === projectName) {
const className = names.getClassName(value.path);
classNameToModuleContentText[className] = value.content;
}
cursor.continue();
Expand Down Expand Up @@ -602,7 +603,7 @@ class ClientSideStorage implements commonStorage.Storage {
for (const className in classNameToModuleType) {
const moduleType = classNameToModuleType[className];
const moduleContentText = classNameToModuleContentText[className];
const modulePath = commonStorage.makeModulePath(projectName, className);
const modulePath = names.makeModulePath(projectName, className);
const getRequest = modulesObjectStore.get(modulePath);
getRequest.onerror = () => {
console.log('IndexedDB get request failed. getRequest.error is...');
Expand Down
Loading