Ejemplo n.º 1
0
	def create_nav_bar(self,_controllers):
		controllers=_controllers[:]

		component_path=self.project_path_resources+"/js/components/navigation-bar"

		if os.path.exists(component_path):
			shutil.rmtree(component_path)

		os.makedirs(component_path)

		s_navigation_controller=""
		for controller in controllers:
			for method in controller["methods"]:
				if "type" in method.keys() and method["type"]=="index":
					s_navigation_controller+="{"
					s_navigation_controller+='"name":"{0}","url":"{1}"'.format(controller["name"],method["route"])
					s_navigation_controller+="},"
		s_navigation_controller=_delete_last_char(s_navigation_controller)
		values={
			"navigation_controllers":s_navigation_controller,
			"use_login":self.login
		}

		content_file=parse_template("./templates/component-navigation-bar.vue",values)
		write_template(component_path+"/navigation-bar.vue",content_file)
		print("Component {0} changed".format("navigation-bar"))
Ejemplo n.º 2
0
    def create_views(self, _views, _components):
        views = _views[:]
        components = _components[:]

        if self.login:
            for view_login in self.views_login:
                views.append(view_login)
            for component_login in self.components_login:
                components.append(component_login)

        views_project_path = self.project_path_resources + "/views"

        if os.path.exists(views_project_path):
            shutil.rmtree(views_project_path)

        os.makedirs(views_project_path + "/templates")
        values = {"use_login": self.login}
        content_file = parse_template("./templates/base.blade.php", values)
        write_template(views_project_path + "/templates/base.blade.php",
                       content_file)

        for view in views:
            views_project_d_path = views_project_path + "/" + view["folder"]

            if not os.path.isdir(views_project_d_path):
                os.makedirs(views_project_d_path)

            s_components_view = ""
            s_components_view_script = ""

            if "components" in view.keys():
                s_components_view = self._create_str_body_view(
                    view, components)

            values_views = {
                "components": s_components_view,
                "script_components": s_components_view_script,
                "title": view["name"]
            }

            content_file = parse_template("./templates/view.blade.php",
                                          values_views)
            write_template(
                views_project_d_path + "/{0}.blade.php".format(view["name"]),
                content_file)

            print("View {0} generated".format(view["name"]))
Ejemplo n.º 3
0
	def create_models(self,_models):
		models=_models[:]
		_delete_files(self.project_path_app)
			
		for model in models:

			model_path_full=self.project_path_app+"/{0}.php".format(model["name"])

			s_fillable=_create_str_array([x["name"] for x in model["fields"]])
			s_hidden=""
			s_casts=""
			s_foreign=""
			s_timestamps=""
			s_primary=""

			for field in model["fields"]:
				if "primary" in field.keys() and field["primary"]:
					s_primary=field["name"]	
				if "references" in field.keys():
					references=field["references"]
					values_function={
						"function_name":references["name"].lower(),
						"function_parameters":"",
						"type":"foreign",
						"reference":references["type"],
						"field":references["field"],
						"table_name":references["name"]
					}
					s_foreign+=parse_template("./templates/function-foreign.php",values_function)
			s_foreign=_delete_last_char(s_foreign,["\n"])
			values={
				"name":model["name"],
				"fillable":s_fillable,
				"hidden":s_hidden,
				"casts":s_casts,
				"foreign":s_foreign,
				"timestamps":field["type"]=="timestamps",
				"primary":s_primary
			}

			content_file=parse_template("./templates/model.php",values)
			write_template(model_path_full,content_file)

			print("Model {0} changed".format(model["name"]))
    def create_middlewares(self, _middlewares=[]):
        middlewares = _middlewares[:]
        s_middlewares = ""

        excludes = [
            "Authenticate.php", "CheckForMaintenanceMode.php",
            "EncryptCookies.php", "RedirectIfAuthenticated.php",
            "TrimStrings.php", "TrustProxies.php", "VerifyCsrfToken.php"
        ]

        _delete_files(self.project_path_app + "/Http/Middleware",
                      excludes,
                      equals=True)

        if self.login:
            for middleware_login in self.middlewares_login:
                middlewares.append(middleware_login)

        for middleware in middlewares:
            os.system("php " + self.project_path_full +
                      "/artisan make:middleware " + middleware["name"])

            values = {
                "type": '"' + middleware["type"] + '"',
                "name": middleware["name"]
            }

            content_file = parse_template("./templates/middleware.php", values)
            write_template(
                self.project_path_app +
                "/Http/Middleware/{0}.php".format(middleware["name"]),
                content_file)

            s_middlewares += "\t\t'{0}'=>\App\Http\Middleware\{1}::class,".format(
                middleware["alias"], middleware["name"])

        values = {"middlewares": s_middlewares}

        content_file = parse_template("./templates/Kernel.php", values)
        write_template(self.project_path_app + "/Http/Kernel.php",
                       content_file)
Ejemplo n.º 5
0
	def _create_str_migration(self,model):
		s_migration_content=""
		for field in model["fields"]:

			migration_template='\t\t\t$table->#type#("#name#")#constraint#;\n'

			if field["type"]=="timestamps":
				migration_template="\t\t\t$table->#type#;\n"

			s_constraint=""

			if "constraint" in field.keys():
				for contraint in field["constraint"]:
					s_constraint+="->"+contraint;

			values_migration={
				"type":field["type"],
				"name":field["name"],
				"constraint":s_constraint
			}

			s_migration_content+=parse_template(migration_template,values_migration,False)

			if "references" in field.keys():
				references=field["references"]
				references_template='\t\t\t$table->foreign("#field_1#")->references("#field_2#")->on("#table#s");\n'
				
				values_references={
					"field_1":field["name"],
					"field_2":references["field"],
					"table":references["name"].lower()
				}

				if "primary" in field.keys():
					if not field["primary"]:
						s_migration_content+=parse_template(references_template,values_references,False)
				else:
					s_migration_content+=parse_template(references_template,values_references,False)

		return _delete_last_char(s_migration_content,[",","\n"])
Ejemplo n.º 6
0
    def create_route(self, _controllers):
        s_route = ""
        controllers = _controllers[:]

        if self.login:
            for controller_login in self.controllers_login:
                controllers.append(controller_login)

        for controller in controllers:
            s_route += self._create_str_route(controller) + "\n"

        values_route = {"routes": s_route}

        content_file = parse_template("./templates/web.php", values_route)
        write_template(self.project_path_routes + "/web.php", content_file)

        print("Web file changed")
Ejemplo n.º 7
0
	def _create_str_component_form(self,model_selected):
		s_component_form=""
		for field in model_selected["fields"]:
			if field["type"]=="increments":
				continue
			s_component_form+="\t\t\t\t<label>{0}</label>\n".format(field["name"])

			input_template="\t\t\t\t<input type='#type#' v-model='item.#name#' value='item.#name#' name='#name#'/>\n"

			s_type="text"
			if field["type"]=="integer":
				s_type="number"

			values={
				"type":s_type,
				"name":field["name"]
			}

			s_component_form+=parse_template(input_template,values,False)
		s_component_form=_delete_last_char(s_component_form,["\n"])
		return s_component_form
Ejemplo n.º 8
0
    def _create_str_route(self, controller):
        s_route = ""
        route_template = ""

        for method in controller["methods"]:
            s_middlewares = ""

            if "middlewares" in method.keys():
                route_template = 'Route::#method#("#route#","#controller#@#function#")->middleware(#middlewares#);\n'
                s_middlewares = _create_str_array(method["middlewares"])
            else:
                route_template = 'Route::#method#("#route#","#controller#@#function#");\n'

            values = {
                "method": method["method"].lower(),
                "route": method["route"],
                "controller": controller["name"],
                "function": method["name"],
                "middlewares": s_middlewares
            }
            s_route += parse_template(route_template, values, False)
        return s_route
Ejemplo n.º 9
0
	def create_migrations(self,models,migrate=True):

		excludes=[
			"create_users_table",
			"create_failed_jobs_table"
		]

		_delete_files(self.project_path_migrations,excludes)

		for model in models:

			migration_name="create_"+model["name"].lower()+"s_table"

			if migration_name!="create_users_table":
				os.system("php "+self.project_path_full+"/artisan make:migration "+migration_name)
			
			s_migration_content=self._create_str_migration(model)

			values={
				"name":model["name"].replace("_",""),
				"migration_name":model["name"].lower(),
				"migration_content":s_migration_content
			}

			s_migration=parse_template("./templates/migration.php",values)

			migrations = os.listdir(self.project_path_migrations)

			for migration in migrations:
				if migration_name in migration:
					write_template(self.project_path_migrations+"/{0}".format(migration),s_migration)
					print("Migration {0} changed".format(migration))
					break
		if migrate:
			os.system("php "+self.project_path_full+"/artisan migrate")
		else:
			os.system("php "+self.project_path_full+"/artisan migrate:fresh")
Ejemplo n.º 10
0
	def create_components(self,_components,_views,_controllers,_models):
		components=_components[:]
		views=_views[:]
		models=_models[:]
		controllers=_controllers[:]

		if self.login:
			for view_login in self.views_login:
				views.append(view_login)
			for component_login in self.components_login:
				components.append(component_login)
			for controller_login in self.controllers_login:
				controllers.append(controller_login)

		path_template_app="./templates/app.js"
		content_file=parse_template(path_template_app,{})
		write_template(self.project_path_resources+"/js/app.js",content_file)

		component_path=self.project_path_resources+"/js/components"

		if os.path.exists(component_path):
			shutil.rmtree(component_path)

		os.makedirs(component_path)

		for component in components:
			view_selected=self._find_view_by_component(views,component)
			if not view_selected:
				continue

			project_component_d_path=self.project_path_resources+"/js/components/{0}".format(view_selected["folder"])
			if not os.path.isdir(project_component_d_path):
				os.makedirs(project_component_d_path)

			controller_selected=self._find_controller_by_view(controllers,view_selected)
			
			s_component_form=""
			s_model_json=""

			s_items=""
			s_props=""
			s_http=""

			types=["create","delete","update","select","index","login","register"]
			urls=["","","","","","",""]
			methods=["","","","","","",""]
			https=["http","http","http","http","http","http","http"]

			if component["type"]=="login":
				model={
					"name":"_login",
					"fields":[]
				}

				method=_find(controller_selected["methods"],"login","type")

				for b_params in method["body-params"]:
					model["fields"].append({
						"name":b_params,
						"type":"string"
					})

				models.append(model)
				controller_selected["model"]="_login"

			if controller_selected and "model" in controller_selected.keys():
				model_selected=_find(models,controller_selected["model"])
				if model_selected:
					s_component_form=self._create_str_component_form(model_selected)
					s_model_json=self._create_str_json(model_selected)

					for i,_type in enumerate(types):
						method=_find(controller_selected["methods"],_type,"type")
						if method:
							if _type=="select":
								urls[i]="'"+method["route"].replace("{","'+it.").replace("}","")
							else:
								urls[i]=method["route"]

							methods[i]=method["method"].lower()

							if "request-type" in method.keys():
								https[i]=method["request-type"]


			if "props" in component.keys():
				s_items= component["props"][0]
				s_props+=_create_str_array(component["props"][1:])

			values={

				"component_form":s_component_form,
				"model_json":s_model_json,
				"props":s_props,

				"url_add":urls[0],
				"url_remove":urls[1],
				"url_update":urls[2],
				"url_select":urls[3],
				"url_redirect":urls[4],
				"url_login":urls[5],

				"method_add":methods[0],
				"method_remove":methods[1],
				"method_update":methods[2],
				"method_login":methods[5],

				"add":urls[0]!="",
				"update":urls[1]!="",
				"remove":urls[2]!="",

				"http_add":https[0]=="http",
				"http_remove":https[1]=="http",
				"http_update":https[2]=="http",
				"http_login":https[5]=="http",
				
				"items":s_items,
			}

			path_template="./templates/component-blank.vue"
			if "type" in component.keys():
				if component["type"]=="complete":
					path_template="./templates/component-model-normal.vue"
				elif component["type"]=="individual":
					path_template="./templates/component-model-individual.vue"

				elif component["type"]=="login":
					path_template="./templates/component-model-login.vue"
				elif component["type"]=="register":
					path_template="./templates/component-model-register.vue"


			content_file=parse_template(path_template,values)
			write_template(project_component_d_path+"/{0}.vue".format(component["name"]),content_file)

			print("Component {0} changed".format(component["name"]))
    def create_controllers(self, _controllers, _models, _views):
        controllers = _controllers[:]
        models = _models[:]
        views = _views[:]

        if self.login:
            for controller_login in self.controllers_login:
                controllers.append(controller_login)
            for view_login in self.views_login:
                views.append(view_login)

        excludes = [
            "Controller.php",
        ]

        _delete_files(self.project_path_app + "/Http/Controllers/",
                      excludes,
                      equals=True)

        for controller in controllers:

            os.system("php " + self.project_path_full +
                      "/artisan make:controller " + controller["name"])

            s_imports = ""
            s_methods = ""
            s_primary = ""

            model_selected = None
            model_selected_aux = None
            if "model" in controller.keys():
                model_selected = _find(models, controller["model"])
                model_selected_aux = model_selected
                s_imports = self._create_str_imports(model_selected)

            for method in controller["methods"]:
                s_parameters = self._create_str_parameters(method)

                if "use-model" in method.keys() and not method["use-model"]:
                    model_selected = None
                else:
                    model_selected = model_selected_aux

                if model_selected:
                    for field in model_selected["fields"]:
                        pass

                values_method = {
                    "function_name": method["name"],
                    "function_parameters": s_parameters,
                    "type": "blank",
                    "model_selected": model_selected,
                    "primary": s_primary,
                    "name_lower": None,
                    "name_normal": None,
                    "request-type": "http",
                    "view_selected": None,
                    "folder": None,
                    "view": None,
                    "credentials": None,
                    "set_attributes": None,
                    "find": None,
                    "update": None
                }

                if model_selected:
                    values_method["name_lower"] = model_selected["name"].lower(
                    )
                    values_method["name_normal"] = model_selected["name"]

                if "request-type" in method.keys():
                    values_method["request-type"] = method["request-type"]

                if "view" in method.keys():
                    view_selected = _find(views, method["view"])
                    values_method["view_selected"] = view_selected
                    if view_selected:
                        values_method["folder"] = view_selected["folder"]
                        values_method["view"] = view_selected["name"]

                path_template = "./templates/function-blank.php"
                if "type" in method.keys():
                    path_template = "./templates/function-{0}.php".format(
                        method["type"])
                    if method["type"] == "login":
                        if "body-params" in method.keys():
                            values_method["credentials"] = _create_str_array(
                                method["body-params"])
                    elif method["type"] == "register" or method[
                            "type"] == "create":
                        values_method[
                            "set_attributes"] = self._create_str_set_attributes(
                                model_selected)
                    elif method["type"] == "delete" or method[
                            "type"] == "update" or method["type"] == "select":
                        if method["type"] == "update":
                            values_method["update"] = self._create_str_update(
                                model_selected)
                        values_method["find"] = self._create_str_find_one(
                            model_selected, method)

                s_methods += parse_template(path_template, values_method)

            s_methods = _delete_last_char(s_methods, ["\n"])

            values_controller = {
                "imports": s_imports,
                "name": controller["name"],
                "methods": s_methods
            }

            content_file = parse_template("./templates/controller.php",
                                          values_controller)
            write_template(
                self.project_path_app +
                "/Http/Controllers/{0}.php".format(controller["name"]),
                content_file)

            print("Controller {0} changed".format(controller["name"]))