Skip to content

Commit

Permalink
change(all): Move all remaining JS files to Typescript (#2875)
Browse files Browse the repository at this point in the history
* Convert files that don't throw errors

* Import lodash in all missing files

* Missing lodash imports

* One missing file

* Convert more files to typescript

* Move more files

* Restore to branch version

* Move more files

* Move more files

* wip

* Last files

* Fix lint

* Some window variables

* Add angular type check

* js is now ts on tests

* yarn

* Change promise resolution

* Allow karma to run typescript files

* Fix issues with tslint

* Missing )

* Fix tsc issues

* Get old react functions back (fix e2e)

* No tson

* Fix e2e and lint errors

* Delete unused returns

* Fix tslint

* Add one more property from merge

* Fix more lint issues

* Remove any type

* Example server -> js

* Trailing comma
  • Loading branch information
pablopunk authored Mar 21, 2019
1 parent eb4544b commit 6cd1f22
Show file tree
Hide file tree
Showing 297 changed files with 1,414 additions and 908 deletions.
12 changes: 6 additions & 6 deletions jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"jsx": "preserve",
"paths": {
"apps/*": [
"./scripts/apps/*",
"./scripts/apps/*"
],
"core/*": [
"./scripts/core/*",
],
"./scripts/core/*"
]
},
"baseUrl": ".",
"baseUrl": "."
},
"exclude": [
"node_modules",
"bower_components",
"po",
"po"
]
}
}
11 changes: 7 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


var grunt = require('grunt');
var makeConfig = require('./webpack.config.js');

Expand All @@ -25,7 +23,7 @@ module.exports = function(config) {

preprocessors: {
'**/*.html': ['ng-html2js'],
'scripts/tests.js': ['webpack', 'sourcemap'],
'scripts/tests.ts': ['webpack', 'sourcemap'],
},

webpack: webpackConfig,
Expand All @@ -40,7 +38,7 @@ module.exports = function(config) {
},

files: [
'scripts/tests.js',
'scripts/tests.ts',
'scripts/**/*.html',
],

Expand Down Expand Up @@ -69,5 +67,10 @@ module.exports = function(config) {

// Seams default 10s is not enough for CI sometime, so let's try 30s
browserNoActivityTimeout: 30000,

// Allow typescript files
mime: {
'text/x-typescript': ['ts', 'tsx'],
},
});
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"main": "scripts/index.js",
"dependencies": {
"@types/angular": "1.6.50",
"@types/draft-js": "0.10.25",
"@types/draft-js": "0.10.29",
"@types/lodash": "4.14.117",
"@types/react": "16.4.9",
"@types/react-dom": "16.8.0",
Expand Down Expand Up @@ -111,6 +111,9 @@
"webpack-dev-server": "2.11.1"
},
"devDependencies": {
"@types/moment": "^2.13.0",
"@types/moment-timezone": "^0.5.12",
"@types/webpack-env": "^1.13.9",
"btoa": "^1.1.2",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import _ from 'lodash';

export class BaseListController {
lastQueryParams: any;
$location: any;
search: any;
desks: any;

constructor($scope, $location, search, desks) {
this.lastQueryParams = {};
this.$location = $location;
Expand All @@ -11,7 +18,7 @@ export class BaseListController {
const source = this.getQuery(null, $scope.repo.archive || false);

source.from = from;
this.fetchItems(this.getCriteria(source), true);
this.fetchItems(this.getCriteria(source));
};

$scope.$on('$routeUpdate', (e, data) => {
Expand Down Expand Up @@ -55,12 +62,13 @@ export class BaseListController {
return query;
}

fetchItems(criteria) {
fetchItems(criteria, next?) {
console.warn('No API defined.');
}

fetchItem(id) {
console.warn('no api defined');
return Promise.resolve();
}

refresh(filterDesk) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function ArchivedItemKill(authoring, api, notify) {
api.remove(itemToDelete, {}, 'archived').then(
(response) => {
var fields = _.union(_.keys(authoring.getContentFieldDefaults()), ['_id', 'versioncreated']);
var itemForTemplate = {template_name: scope.action, item: _.pick(scope.item, fields)};
let itemForTemplate: any = {template_name: scope.action, item: _.pick(scope.item, fields)};

api.save('content_templates_apply', {}, itemForTemplate, {}).then((result) => {
itemForTemplate = _.pick(result, _.keys(authoring.getContentFieldDefaults()));
Expand All @@ -38,7 +38,7 @@ export function ArchivedItemKill(authoring, api, notify) {
} else {
notify.error(gettext('Unknown Error: Cannot kill the item'));
}
}
},
);

scope.kill = function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

ContentResults.$inject = ['$location', 'preferencesService', 'packages', 'tags', 'asset', 'search'];

/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import _ from 'lodash';

class LinkFunction {
api: any;
config: any;
multi: any;
notify: any;
storage: any;
session: any;
urls: any;
scope: any;

constructor(api, config, multi, notify, storage, session, urls, scope) {
this.api = api;
this.config = config;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

/**
* @ngdoc directive
* @module superdesk.apps.archive
Expand Down Expand Up @@ -32,7 +34,7 @@ export function ItemCrops(metadata) {
scope.showCrops = () => (
_.includes(['picture', 'graphic'], scope.item.type) && _.get(metadata, 'values.crop_sizes') &&
metadata.values.crop_sizes.some(
(crop) => scope.item.renditions && scope.item.renditions[crop.name]
(crop) => scope.item.renditions && scope.item.renditions[crop.name],
)
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

ItemLock.$inject = ['api', 'lock', 'privileges', 'desks'];
export function ItemLock(api, lock, privileges, desks) {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import _ from 'lodash';

class LinkFunction {
scope: any;
desks: any;
authoring: any;
highlightsService: any;
filter: any;
location: any;
timeout: any;
elem: any;

constructor(desks, authoring, highlightsService, $filter, $location, $timeout, scope, elem) {
this.desks = desks;
this.authoring = authoring;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

MediaMetadata.$inject = ['userList', 'archiveService', 'metadata'];

export function MediaMetadata(userList, archiveService, metadata) {
Expand Down Expand Up @@ -38,7 +40,7 @@ export function MediaMetadata(userList, archiveService, metadata) {
}

scope.getLocaleName = function(terms, scheme) {
const term = terms.find((elem) => elem.scheme === scheme);
const term = terms.find((element) => element.scheme === scheme);

if (!term) {
return 'None';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

/**
* @ngdoc directive
* @module superdesk.apps.archive
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class LinkFunction {
scope: any;
superdesk: any;
api: any;
familyService: any;

constructor(superdesk, api, familyService, scope) {
this.scope = scope;
this.superdesk = superdesk;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

MediaView.$inject = ['keyboardManager', 'packages'];

export function MediaView(keyboardManager, packages) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import {gettext} from 'core/utils';

ResendItem.$inject = ['subscribersService', 'authoring', 'api', 'notify'];
Expand All @@ -14,8 +15,8 @@ export function ResendItem(subscribersService, authoring, api, notify) {
subscribersService.fetchTargetableSubscribers().then((items) => {
scope.customSubscribers = [];
scope.subscribers = items._items;
_.each(items, (item) => {
scope.customSubscribers.push({qcode: item._id, name: item.name});
_.each(items, (_item) => {
scope.customSubscribers.push({qcode: _item._id, name: _item.name});
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import './styles/related-item.scss';
import './styles/assignment.scss';
import './styles/html-preview.scss';
import {get} from 'lodash';
import {get, includes} from 'lodash';

// scripts
import './related-item-widget/relatedItem';
Expand Down Expand Up @@ -392,7 +392,7 @@ function spikeActivity(spike, data, modal, $location, $q, multi, privileges,
authoringWorkspace, confirm, autosave, config) {
// For the sake of keyboard shortcut to work consistently,
// if the item is multi-selected, let multibar controller handle its spike
if (!data.item || multi.count > 0 && _.includes(multi.getIds(), data.item._id)) {
if (!data.item || multi.count > 0 && includes(multi.getIds(), data.item._id)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash';
import moment from 'moment';

ArchiveService.$inject = ['desks', 'session', 'api', '$q', 'search', '$location', 'config'];
export function ArchiveService(desks, session, api, $q, search, $location, config) {
Expand Down Expand Up @@ -81,7 +82,7 @@ export function ArchiveService(desks, session, api, $q, search, $location, confi
this.getRelatedItems = function(item, fromDateTime) {
var beforeDateTime = fromDateTime || moment().subtract(1, 'days')
.format(config.view.dateformat);
var params = {};
var params: any = {};

params.q = 'slugline.phrase:"' + _.trim(item.slugline) + '"'; // exact match
params.ignoreKilled = true;
Expand All @@ -93,7 +94,7 @@ export function ArchiveService(desks, session, api, $q, search, $location, confi
query.size(200);

if (_.get(item, '_id')) {
let filter = {
let filter: any = {
bool: {
must_not: [
{bool: {must: [{term: {_id: item._id}}, {term: {_type: 'archive'}}]}},
Expand Down Expand Up @@ -132,11 +133,11 @@ export function ArchiveService(desks, session, api, $q, search, $location, confi
* Returns versions of the item.
*
* @param {Object} item
* @param {Object} desks deskService
* @param {Object} deskService
* @param {String} versionType one of versions, operations
* @return list of object where each object is a version of the item
*/
this.getVersions = function(item, desks, versionType) {
this.getVersions = function(item, deskService, versionType) {
if (this.isLegal(item)) {
return api.find('legal_archive', item._id, {version: 'all', max_results: 200})
.then((result) => {
Expand Down Expand Up @@ -165,18 +166,19 @@ export function ArchiveService(desks, session, api, $q, search, $location, confi
_.each(result._items, (version) => {
if (version.task) {
if (version.task.desk) {
var versiondesk = desks.deskLookup[version.task.desk];
var versiondesk = deskService.deskLookup[version.task.desk];

version.desk = versiondesk && versiondesk.name;
}
if (version.task.stage) {
var versionstage = desks.stageLookup[version.task.stage];
var versionstage = deskService.stageLookup[version.task.stage];

version.stage = versionstage && versionstage.name;
}
}
if (version.version_creator || version.original_creator) {
var versioncreator = desks.userLookup[version.version_creator || version.original_creator];
var versioncreator =
deskService.userLookup[version.version_creator || version.original_creator];

version.creator = versioncreator && versioncreator.display_name || 'System';
}
Expand Down Expand Up @@ -208,6 +210,8 @@ export function ArchiveService(desks, session, api, $q, search, $location, confi
return _.find(versions, {_current_version: item._latest_version});
}

return _.max(versions, (version) => version._current_version || version.version);
const versionsMap = versions.map((v) => v._current_version || v.version);

return _.max(versionsMap);
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {get} from 'lodash';
import _, {get} from 'lodash';

/**
* @ngdoc service
Expand All @@ -13,7 +13,6 @@ FamilyService.$inject = ['api', 'desks'];
export function FamilyService(api, desks) {
const repo = 'archive,published';


/**
* @ngdoc method
* @name family#fetchItems
Expand All @@ -24,7 +23,7 @@ export function FamilyService(api, desks) {
* @returns {Object}
*/
this.fetchItems = (familyId, excludeItem) => {
let filter = [
let filter: Array<any> = [
{not: {term: {state: 'spiked'}}},
{term: {family_id: familyId}},
];
Expand Down Expand Up @@ -64,8 +63,8 @@ export function FamilyService(api, desks) {
* @param {Object} queryString
* @returns {Object}
*/
const query = (filter, sortField, order, queryString) => {
let params = {
const query = (filter: any, sortField: string, order: string, queryString?: string) => {
let params: any = {
repo: repo,
source: {
query: {filtered: {filter: {
Expand Down Expand Up @@ -115,7 +114,7 @@ export function FamilyService(api, desks) {
* @returns {Object}
*/
this.fetchRelatableItems = (keyword, sluglineMatch, item, modificationDateAfter) => {
let filter = [
let filter: Array<any> = [
{not: {term: {state: 'spiked'}}},
{not: {term: {event_id: item.event_id}}},
{not: {term: {type: 'composite'}}},
Expand All @@ -142,7 +141,7 @@ export function FamilyService(api, desks) {

// process creation date
if (modificationDateAfter) {
let dateQuery = {};
let dateQuery: any = {};

dateQuery.versioncreated = {
gte: modificationDateAfter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

/**
* @ngdoc service
* @module superdesk.apps.archive
Expand Down
Loading

0 comments on commit 6cd1f22

Please sign in to comment.