why cannot export file as a module into another module in nodejs - module

I have created add value function which is in tacas.js file I wanted to exported to another module:
code in tacas.js was:
const num1 = 5
const num2 = 10
function addValues() {
console.log(the sum is : ${num1 + num2})
}
addValues()
wanted to export into another module, which is app.js,
and there code was :
require('./tacas')
and executed through CMD terminal,but nothing returns.
please help
require('./tacas')

Related

Prestashop 1.7.7.5: FrameworkBundleAdminController: $this->module->getPathUri() returns an error

In my admin module's controller's listMappingsAction action, I want to show a Vue.JS template, passing two variables that need to call $this->module->getPathUri() to be assigned a value:
<?php
namespace XYZ\Controller;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Security\Annotation\AdminSecurity;
class AutomatizedMappingController extends FrameworkBundleAdminController
{
/**
* #AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.")
*/
function listMappingsAction() {
return $this->render('#Modules/XYZ/views/templates/admin/app.html.twig', [
'XYZ' => [
'pathApp' => $this->module->getPathUri() . 'views/js/app.js',
'chunkVendor' => $this->module->getPathUri() . 'views/js/chunk-vendors.js',
]
]);
}
}
The use of $this->module->getPathUri() results in this error being displayed:
Attempted to call an undefined method named "getPathUri" of class "XYZ\Controller\AutomatizedMappingController". [Symfony\Component\Debug\Exception\UndefinedMethodException 0]
What could I call to make it work? The docs don't mention this use case... https://devdocs.prestashop.com/1.7/modules/concepts/templating/vuejs/faq/#how-to-send-data-from-symfony-controller-to-vuejs
First of all you need to know there is a difference between a module and a admin-controller. You cannot call $this->module->getPathUri() because your not using a extends ModuleAdminController, extends ModuleFrontController, extends Module ...
So you can only call $this->module if your actually using files inside a module.
Since i don't know which path you are trying to go to ill pass you a few variables which you might be able to use.
$this->module->name = crezzurmodulename
$this->module->getLocalPath() = C:\yourstore/modules/crezzurmodulename/
$this->module->getPathUri() = /yourstore/modules/crezzurmodulename/
_MODULE_DIR_ = /yourstore/modules/
_PS_MODULE_DIR_ = C:\yourstore/modules/
__DIR__ = C:\yourstore\modules\crezzurmodulename\controllers\front
_PS_CAT_IMG_DIR_ = C:\yourstore/img/c/
_PS_PROD_IMG_DIR_ = C:\yourstore/img/p/
_PS_TMP_IMG_DIR_ = C:\yourstore/img/tmp/
_PS_ROOT_DIR_ = C:\yourstore
_PS_CACHE_DIR_ = C:\yourstore/var/cache/dev\
_PS_BASE_URL_ = http://127.0.0.1
__PS_BASE_URI__ = /yourstore/
_PS_TRANSLATIONS_DIR_ = C:\yourstore/translations/
_PS_BASE_URL_SSL_ = http://127.0.0.1 or https://127.0.0.1
_PS_DOWNLOAD_DIR_ = C:\yourstore/download/
_PS_COL_IMG_DIR_ = C:\yourstore/img/co/
_PS_SHIP_IMG_DIR_ = C:\yourstore/img/s/
_PS_UPLOAD_DIR_ = C:\yourstore/upload/

How to pass an array as a parameter to statementExecPromisified(statement,[]) function of sap-hdbext-promisfied in nodejs?

I have an array of users as below
let usersarr = ["'SAC_XSA_HDB_USER_ABC','SAC_XSA_HDB_USER_DEF'"]
I want to fetch data about the above users(if exists) from Hana database. I am using sap-hdbext-promisfied library in node.js.
My database connection is working fine. So, I am trying to execute a select query as below
async function readUsers(xsaDbConn){
try{
let usersarr = ["'SAC_XSA_HDB_USER_ABC','SAC_XSA_HDB_USER_DEF'"]
const checkuserexiststatement = await xsaDbConn.preparePromisified("SELECT USER_NAME FROM USERS WHERE USER_NAME IN (?)")
let checkuserexistresult = await xsaDbConn.statementExecPromisified(checkuserexiststatement, [usersarr])
console.log(checkuserexistresult)
return checkuserexistresult
}catch(err){
console.log(err)
return;
}
}
Below is the output I get
PS C:\Users\Documents\XSA\SAC_POC\cap_njs> npm start
> cap_njs#1.0.0 start C:\Users\Documents\XSA\SAC_POC\cap_njs
> node server.js
myapp is using Node.js version: v12.18.3
myapp listening on port 3000
[]
I get an empty array object as output. This is not the expected output, instead it should provide details about the users as they exist in the database.
The above code works when I provide single user value instead of multiple users in an array as shown below
async function readUsers(xsaDbConn, tempxsahdbusers){
try{
let usersarr = 'SAC_XSA_HDB_USER_ABC'
const checkuserexiststatement = await xsaDbConn.preparePromisified("SELECT USER_NAME FROM USERS WHERE USER_NAME IN (?)")
let checkuserexistresult = await xsaDbConn.statementExecPromisified(checkuserexiststatement, [usersarr])
console.log(checkuserexistresult)
return checkuserexistresult
}catch(err){
console.log(err)
return;
}
}
Output Of Above Code -
PS C:\Users\Documents\XSA\SAC_POC\cap_njs> npm start
> cap_njs#1.0.0 start C:\Users\Documents\XSA\SAC_POC\cap_njs
> node server.js
myapp is using Node.js version: v12.18.3
myapp listening on port 3000
[ 'SAC_XSA_HDB_USER_ABC' ]
So, why is it giving an empty array object when I provide an array as a parameter instead of a variable? Is it possible to provide an array as a parameter to the function statementExecPromisified(statement, []) of sap-hdbext-promisfied library in node.js ?
Your
let usersarr = ["'SAC_XSA_HDB_USER_ABC','SAC_XSA_HDB_USER_DEF'"]
has exactly one value, the String:
"'SAC_XSA_HDB_USER_ABC','SAC_XSA_HDB_USER_DEF'"
When passing the userarr in the statementExecPromisified function as a parameter you are actually passing a nested array in an array. You could either try
xsaDbConn.statementExecPromisified(checkuserexiststatement, [usersarr[0]])
or separate the values in the userarr and add multiple ? in the prepared statement and reference each single value with userarr[x].

Drupal 8: When I update the node field to a specific value, how to call my module (managefinishdate.module) to update another field?

I am having a node type with machine name to_do_item, and I want to create a module called managefinishdate to update the node: when a user edit the node's field (field_status) to "completed" and click "save", then the module will auto update the field_date_finished to current date.
I have tried to create the module and already success to install in "Extend":
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
...
}
however, I am not sure is this module being called, because whatever I echo inside, seems nothing appeared.
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
/** * Implements hook_ENTITY_TYPE_update().
* If a user update status to Completed,
* update the finished date as save date
*/
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
$node = \Drupal::routeMatch()->getParameter('node');
print_r($node);
//$entity_type = 'node';
//$bundles = ['to_do_item'];
//$fld_finishdate = 'field_date_finished';
//if ($entity->getEntityTypeId() != $entity_type || !in_array($entity->bundle(), $bundles)) {
//return;
//}
//$current_date=date("Y-m-d");
//$entity->{$fld_finishdate}->setValue($current_date);
}
Following Drupal convention, your module named 'manage_finish_date' should contain a 'manage_finish_date.module file that sits in the root directory that should look like this:
<?php
use Drupal\node\Entity\Node;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function manage_finish_date_node_insert(Node $node) {
ManageFinishDate::update_time();
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function manage_finish_date_node_update(Node $node) {
ManageFinishDate::update_time();
}
You should also have another file called 'src/ManageFinishDate.php' that should look like this:
<?php
namespace Drupal\manage_finish_date;
use Drupal;
use Drupal\node\Entity\Node;
class ManageFinishDate {
public static function update_time($node, $action = 'create') {
// Entity bundles to act on
$bundles = array('to_do_item');
if (in_array($node->bundle(), $bundles)) {
// Load the node and update
$status = $node->field_status->value;
$node_to_update = Node::load($node);
if ($status == 'completed') {
$request_time = Drupal::time();
$node_to_update->set('field_date_finished', $request_time);
$node_to_update->save();
}
}
}
}
The code is untested, but should work. Make sure that the module name, and namespace match as well as the class filename and class name match for it to work. Also, clear you cache once uploaded.
This will handle newly created and updated nodes alike.
Please look after this sample code which may help you:
function YOUR_MODULE_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
switch ($entity->bundle()) {
//Replace CONTENT_TYPE with your actual content type
case 'CONTENT_TYPE':
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
// Set the current date
}
break;
}
}

How to use ENQUEUEGETSTAT function module in Gateway service

How can I use ENQUEUEGETSTAT function module in gateway service, this fm returns 3 parameter (ENTRIES_TOTAL, ENTRIES_PEAK, ENTRIES_ACTUAL)
I can map tables in Gateway but cant figure out this. How can I collect these parameters in to internal table and export then?
it looks like a function import use case to me .
First of all, you have to define a ABAP structure for the returning data like below
#EndUserText.label : 'ENQUEUEGETSTAT'
#AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
define structure zza_enqueuegetstat {
entries_total : abap.int4;
entries_peak : abap.int4;
entries_actual : abap.int4;
}
In your SEGW project, create a entity type ENQUEUEGETSTAT mapping to this structure.
.
Afterwards, create a function import ENQUEUEGETSTAT.
Go to your DPC_EXT class and redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~EXECUTE_ACTION.
method /iwbep/if_mgw_appl_srv_runtime~execute_action.
data ls_enqueuegetstat type zza_enqueuegetstat.
if iv_action_name = 'ENQUEUEGETSTAT'.
call function 'ENQUEUEGETSTAT'
importing
entries_total = ls_enqueuegetstat-entries_actual
entries_peak = ls_enqueuegetstat-entries_peak
entries_actual = ls_enqueuegetstat-entries_total.
copy_data_to_ref(
exporting
is_data = ls_enqueuegetstat
changing
cr_data = er_data
).
endif.
endmethod.
Save and activate everything. Then you should able to access your function import /sap/opu/odata/sap/**YOUR_SERVICE**/ENQUEUEGETSTAT?$format=json
{
"d": {
"EntriesTotal": 382,
"EntriesPeak": 43189,
"EntriesActual": 500000
}
}
Hope it helps.

Override helper list footer in prestashop

I would like to change admin products actions bulks, so i'm creating a module to do the trick,
In my module, i have not any controller, i'm overriding the adminProductsController, and i would like to override ADMIN/themes/default/template/helpers/list/footer_list.tpl, i tried to place it under /override/controllers/admin/templates/helpers/list, but i'm getting the default template.
In Helper.php
public function createTemplate($tpl_name)
{
var_dump($this->override_folder);
var_dump($this->module);
exit;
if ($this->override_folder)
{
if ($this->context->controller instanceof ModuleAdminController)
$override_tpl_path = $this->context->controller->getTemplatePath().$this->override_folder.$this->base_folder.$tpl_name;
elseif ($this->module)
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->override_folder.$this->base_folder.$tpl_name;
else
{
if (file_exists($this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name))
$override_tpl_path = $this->context->smarty->getTemplateDir(1).$this->override_folder.$this->base_folder.$tpl_name;
elseif (file_exists($this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name))
$override_tpl_path = $this->context->smarty->getTemplateDir(0).'controllers'.DIRECTORY_SEPARATOR.$this->override_folder.$this->base_folder.$tpl_name;
}
}
elseif ($this->module)
$override_tpl_path = _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/_configure/'.$this->base_folder.$tpl_name;
I'm getting NULL for $this->override_folder, i tried
$helper->override_folder = $this->tpl_folder;
In AdminController.php, renderList function.
Any one could help?
Thanks.
I solved the problem by adding the file in override/controllers/admin/templates/products/helpers/list