Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imports actualized #1338

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions addon/components/flexberry-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@module ember-flexberry
*/

import Ember from 'ember'; //TODO Import Module. Replace Ember.uuid()
import generateUniqueId from 'ember-flexberry-data/utils/generate-unique-id';
import $ from 'jquery';
import RSVP from 'rsvp';
import { typeOf, isBlank, isNone } from '@ember/utils';
Expand Down Expand Up @@ -63,7 +63,7 @@ export default FlexberryBaseComponent.extend({
let fileInputId = 'flexberry-file-file-input-';
let elementId = this.get('elementId');
if (isBlank(elementId)) {
fileInputId += Ember.uuid();
fileInputId += generateUniqueId();
} else {
fileInputId += elementId;
}
Expand Down
5 changes: 2 additions & 3 deletions addon/components/flexberry/validation-summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
@module ember-flexberry
*/

import Ember from 'ember';

const { Component, computed } = Ember;
import Component from '@ember/component';
import { computed } from '@ember/object';

/**
Component for output messages of validation errors as a [Semantic UI Message](https://semantic-ui.com/collections/message.html) collection.
Expand Down
6 changes: 3 additions & 3 deletions addon/services/compatibility-validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* @module ember-flexberry
*/

import Ember from 'ember';

const { Service, getOwner, set } = Ember;
import Service from '@ember/service';
import { set } from '@ember/object';
import { getOwner } from '@ember/application';
Comment on lines +5 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Update remaining Ember namespace usage for consistency

The verification revealed two types of inconsistencies that need to be addressed:

  • In app-state.js and adv-limit.js: The Ember.Service references appear only in JSDoc comments and don't affect the actual code since both files are already using the imported Service.
  • In user-settings.js: There's an actual usage of Ember.getOwner that should be updated to use the imported version for consistency.

Specific locations needing attention:

  • addon/services/user-settings.js: Replace Ember.getOwner with the imported getOwner from '@ember/application'
🔗 Analysis chain

Verify consistency of import changes across the codebase.

Let's ensure these import changes are consistently applied across all files using these Ember features.


Let me check the specific usage in the files that still use the Ember namespace to determine if there are inconsistencies that need to be addressed.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usage of Ember.Service, Ember.set, and Ember.getOwner
# that might need to be updated for consistency.

echo "Checking for remaining Ember namespace usage..."
rg -l "Ember\.(Service|set|getOwner)" --type js

echo "Verifying new import pattern usage..."
rg -l "import (Service|set|getOwner) from '@ember/" --type js

Length of output: 743


Script:

#!/bin/bash
# Check the actual usage context in files still using Ember namespace
echo "Checking app-state.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/app-state.js -B 2 -A 2

echo -e "\nChecking adv-limit.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/adv-limit.js -B 2 -A 2

echo -e "\nChecking user-settings.js..."
rg "Ember\.(Service|set|getOwner)" addon/services/user-settings.js -B 2 -A 2

Length of output: 985


const EMBER_VALIDATIONS_VALIDATORS = [
'absence',
Expand Down
174 changes: 102 additions & 72 deletions addon/services/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ export default Service.extend(Evented, {

this.initProperties();

let originalEmberLoggerError = Ember.Logger.error;
let originalEmberLoggerError = console.error;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
Comment on lines +378 to +380
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Ensure correct context when caching original console methods

When caching the original console methods, it's important to bind them to the console object to preserve the correct context, especially for methods like console.log.

Modify the caching of the original methods to include binding:

let originalEmberLoggerError = console.error;
+originalEmberLoggerError = originalEmberLoggerError.bind(console);
originalMethodsCache.pushObject({
  methodOwner: console,
  methodName: 'error',
  methodReference: originalEmberLoggerError
});

Repeat this binding for other console methods as needed.

Committable suggestion was skipped due to low confidence.

methodName: 'error',
methodReference: originalEmberLoggerError
});
Expand All @@ -398,111 +398,141 @@ export default Service.extend(Evented, {
_this._onError(reason, true);
};

console.error = function(error) {
originalEmberLoggerError(error);
_this._onError(error, true);
};

console.warn = function(warn) {
originalEmberLoggerError(warn);
_this._onError(warn, true);
};
Comment on lines +406 to +409
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Incorrect use of originalEmberLoggerError in console method overrides

In the overridden console methods (warn, deprecated, log, info, debug), you're calling originalEmberLoggerError instead of the corresponding original methods. This causes all logs to be treated as errors, which may lead to incorrect logging levels and confusion.

To fix this, call the appropriate original console method in each override. Ensure that you've cached these original methods correctly.

Apply this diff to fix the issue:

// Override console.warn
console.warn = function(warn) {
-   originalEmberLoggerError(warn);
+   originalEmberLoggerWarn(warn);
    _this._onError(warn, true);
};

// Override console.deprecated
console.deprecated = function(deprecate) {
-   originalEmberLoggerError(deprecate);
+   originalEmberLoggerDeprecate(deprecate);
    _this._onError(deprecate, true);
};

// Override console.log
console.log = function(log) {
-   originalEmberLoggerError(log);
+   originalEmberLoggerLog(log);
    _this._onError(log, true);
};

// Override console.info
console.info = function(info) {
-   originalEmberLoggerError(info);
+   originalEmberLoggerInfo(info);
    _this._onError(info, true);
};

// Override console.debug
console.debug = function(debug) {
-   originalEmberLoggerError(debug);
+   originalEmberLoggerDebug(debug);
    _this._onError(debug, true);
};

Also applies to: 411-414, 416-419, 421-424, 426-429


console.deprecated = function(deprecate) {
originalEmberLoggerError(deprecate);
_this._onError(deprecate, true);
};
Comment on lines +411 to +414
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Usage of non-standard console.deprecated method

The console object does not have a standard deprecated method. Adding non-standard methods to the global console object may lead to confusion and compatibility issues.

Consider using console.warn with a clear deprecation message or creating a custom method within your logging service to handle deprecation notices.


console.log = function(log) {
originalEmberLoggerError(log);
_this._onError(log, true);
};

console.info = function(info) {
originalEmberLoggerError(info);
_this._onError(info, true);
};

console.debug = function(debug) {
originalEmberLoggerError(debug);
_this._onError(debug, true);
};

// Assign Ember.onerror & RSVP.on('error', ...) handlers (see http://emberjs.com/api/#event_onerror).
Ember.onerror = onError;
RSVP.on('error', onPromiseError);

// Extend Ember.Logger.error logic.
Ember.Logger.error = function() {
originalEmberLoggerError(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.error, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// Ember.Logger.error = function() {
// originalEmberLoggerError(...arguments);

// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.error, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };

// Extend Ember.Logger.warn logic.
let originalEmberLoggerWarn = Ember.Logger.warn;
let originalEmberLoggerWarn = console.warn;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'warn',
methodReference: originalEmberLoggerWarn
});

Ember.Logger.warn = function() {
originalEmberLoggerWarn(...arguments);

return _this._queue.attach((resolve, reject) => {
let message = joinArguments(...arguments);
if (message.indexOf('DEPRECATION') === 0) {
return _this._storeToApplicationLog(messageCategory.deprecate, message, '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
} else {
return _this._storeToApplicationLog(messageCategory.warn, message, '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
}
});
};
// Ember.Logger.warn = function() {
// originalEmberLoggerWarn(...arguments);

// return _this._queue.attach((resolve, reject) => {
// let message = joinArguments(...arguments);
// if (message.indexOf('DEPRECATION') === 0) {
// return _this._storeToApplicationLog(messageCategory.deprecate, message, '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// } else {
// return _this._storeToApplicationLog(messageCategory.warn, message, '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// }
// });
// };

// Extend Ember.Logger.log logic.
let originalEmberLoggerLog = Ember.Logger.log;
let originalEmberLoggerLog = console.log.bind;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'log',
methodReference: originalEmberLoggerLog
});

Ember.Logger.log = function() {
originalEmberLoggerLog(...arguments);
// Ember.Logger.log = function() {
// originalEmberLoggerLog(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.log, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.log, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };

// Extend Ember.Logger.info logic.
let originalEmberLoggerInfo = Ember.Logger.info;
let originalEmberLoggerInfo = console.info;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'info',
methodReference: originalEmberLoggerInfo
});

Ember.Logger.info = function() {
originalEmberLoggerInfo(...arguments);
// Ember.Logger.info = function() {
// originalEmberLoggerInfo(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.info, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.info, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };

// Extend Ember.Logger.debug logic.
let originalEmberLoggerDebug = Ember.Logger.debug;
let originalEmberLoggerDebug = console.debug;
originalMethodsCache.pushObject({
methodOwner: Ember.Logger,
methodOwner: console,
methodName: 'debug',
methodReference: originalEmberLoggerDebug
});

Ember.Logger.debug = function() {
originalEmberLoggerDebug(...arguments);

return _this._queue.attach((resolve, reject) => {
return _this._storeToApplicationLog(messageCategory.debug, joinArguments(...arguments), '').then((result) => {
resolve(result);
}).catch((reason) => {
reject(reason);
});
});
};
// Ember.Logger.debug = function() {
// originalEmberLoggerDebug(...arguments);

// return _this._queue.attach((resolve, reject) => {
// return _this._storeToApplicationLog(messageCategory.debug, joinArguments(...arguments), '').then((result) => {
// resolve(result);
// }).catch((reason) => {
// reject(reason);
// });
// });
// };
Comment on lines +436 to +535
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove commented-out code for better maintainability

There are large blocks of commented-out code related to Ember.Logger methods from lines 436 to 535. Keeping obsolete code can clutter the codebase and reduce readability.

If this code is no longer needed, consider removing it to clean up the codebase.


this.set('_originalMethodsCache', originalMethodsCache);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import { A } from '@ember/array';
import { run } from '@ember/runloop';
import { module, skip } from 'qunit';
import startApp from '../../../helpers/start-app';

Expand All @@ -19,15 +20,15 @@ module('Acceptance | flexberry-groupedit | ' + testName, {
},

afterEach() {
Ember.run(app, 'destroy');
run(app, 'destroy');
}
});

skip(testName, (assert) => {
assert.expect(78);
let recordArray = new Ember.A();
let recordArray = new A();

Ember.run(() => {
run(() => {
recordArray.insertAt(0, store.createRecord(
'ember-flexberry-dummy-suggestion',
{
Expand Down Expand Up @@ -129,7 +130,7 @@ skip(testName, (assert) => {
specialArrayCompare(sortResult, [1, 3, 4, 5, 2], assert, 'sortRecords | partial sort | desc');
}
finally {
Ember.run(() => {
run(() => {
recordArray.forEach(currentRecord => {
store.deleteRecord(currentRecord);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Ember from 'ember';
import { set } from '@ember/object';
import { run } from '@ember/runloop';
import $ from 'jquery';
import { module, test } from 'qunit';
import startApp from '../../../helpers/start-app';
import { deleteRecords, addRecords } from './folv-tests-functions';
Expand Down Expand Up @@ -27,13 +29,13 @@ module('Acceptance | flexberry-objectlistview | per page user settings', {
store = app.__container__.lookup('service:store');
route = app.__container__.lookup('route:components-acceptance-tests/flexberry-objectlistview/folv-user-settings');
userService = app.__container__.lookup('service:user-settings')
Ember.set(userService, 'isUserSettingsServiceEnabled', true);
set(userService, 'isUserSettingsServiceEnabled', true);
},

afterEach() {
// Destroy application.
Ember.set(userService, 'isUserSettingsServiceEnabled', true);
Ember.run(app, 'destroy');
set(userService, 'isUserSettingsServiceEnabled', true);
run(app, 'destroy');
}
});

Expand All @@ -49,7 +51,7 @@ test('check saving of user settings', function(assert) {
route.set('developerUserSettings', { FOLVPagingObjectListView: { DEFAULT: { colsOrder: [ { propName: 'name' } ], perPage: 28 } } });

// Add records for paging.
Ember.run(() => {
run(() => {
addRecords(store, modelName, uuid).then(function(resolvedPromises) {
assert.ok(resolvedPromises, 'All records saved.');
let done = assert.async();
Expand Down Expand Up @@ -139,10 +141,10 @@ function checkWithDisabledUserSettings(assert, asyncDone, uuid) {
andThen(function() {
assert.equal(currentPath(), pathHelp);
route.set('developerUserSettings', { FOLVPagingObjectListView: { DEFAULT: { colsOrder: [ { propName: 'name' } ], perPage: 11 } } });
Ember.set(userService, 'isUserSettingsServiceEnabled', false);
set(userService, 'isUserSettingsServiceEnabled', false);

// Remove current saved not in Database settings.
Ember.set(userService, 'currentUserSettings', {});
set(userService, 'currentUserSettings', {});

let done1 = assert.async();
visit(path);
Expand All @@ -155,7 +157,7 @@ function checkWithDisabledUserSettings(assert, asyncDone, uuid) {
} catch(error) {
throw error;
} finally {
Ember.set(userService, 'isUserSettingsServiceEnabled', true);
set(userService, 'isUserSettingsServiceEnabled', true);
deleteRecords(store, modelName, uuid, assert);
deleteUserSetting(assert);
done1();
Expand All @@ -175,14 +177,14 @@ function checkWithDisabledUserSettings(assert, asyncDone, uuid) {
// Function to check current perPage value on page.
function checkPaging(assert, expectedCount) {
// check paging.
let $perPageElement = Ember.$('div.flexberry-dropdown div.text');
let $perPageElement = $('div.flexberry-dropdown div.text');
assert.equal($perPageElement.length, 1, "Элемент количества записей на странице найден.");
assert.equal($perPageElement.text(), expectedCount, `Количество элементов на странице равно заданному: ${expectedCount}.`)
Comment on lines +180 to 182
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider using data-test- selectors for more reliable tests.*

While the jQuery usage is correct, the selector 'div.flexberry-dropdown div.text' is somewhat fragile. Consider using dedicated test selectors for more reliable and maintainable tests.

-  let $perPageElement = $('div.flexberry-dropdown div.text');
+  let $perPageElement = $('[data-test-per-page-dropdown]');

Also update the corresponding component template to include the test selector:

<div class="flexberry-dropdown" data-test-per-page-dropdown>
  <div class="text">
    {{perPage}}
  </div>
</div>

}

// Function for deleting user settings from database.
function deleteUserSetting(assert) {
Ember.run(() => {
run(() => {
let done = assert.async();
userService._getExistingSettings("FOLVPagingObjectListView", "DEFAULT").then(
foundRecords => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Ember from 'ember'; //TODO Import Module. Replace Ember.generateGuid, Ember.Logger
import Ember from 'ember'; //TODO Import Module. Replace Ember.Logger
// import { generateGuid } from '@ember/object/internals';
import generateUniqueId from 'ember-flexberry-data/utils/generate-unique-id';
Comment on lines +1 to +3
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Complete the TODO: Replace Ember.Logger usage with native console methods.

The TODO comment indicates that Ember.Logger needs to be replaced, but the file still uses Ember.Logger in multiple places. This is inconsistent with the PR's goal of actualizing imports.

Replace Ember.Logger with native console methods throughout the file. For example:

-Ember.Logger.error(...)
+console.error(...)

-Ember.Logger.log(...)
+console.log(...)

-Ember.Logger.info(...)
+console.info(...)

Committable suggestion was skipped due to low confidence.

import { computed } from '@ember/object';
import RSVP from 'rsvp';
import { deprecate } from '@ember/application/deprecations';
Expand Down Expand Up @@ -249,7 +251,7 @@ export default ApplicationLogListFormController.extend({
@private
*/
_generateUniqueMessagePrefix() {
return '№' + Ember.generateGuid(null, '') + ': ';
return '№' + generateUniqueId() + ': ';
},

/**
Expand Down
Loading