Anders Kaseorg
09920af211
js: Convert static/js/channel.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
000865ceb1
js: Convert static/js/user_pill.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Anders Kaseorg
a935af9243
js: Convert static/js/pill_typeahead.js to ES6 module.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 10:27:14 -08:00
Anders Kaseorg
aa650a4c88
js: Escape strings interpolated into CSS selectors with CSS.escape.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-04 11:00:06 -08:00
Anders Kaseorg
552f4e3d22
eslint: Fix unicorn/no-array-for-each.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-25 14:53:19 -08:00
Anders Kaseorg
fb233bd994
eslint: Fix unicorn/prefer-number-properties.
...
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-number-properties.md
MDN says these were added to Number for modularization of globals.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
Priyank Patel
b7998d3160
js: Purge people module from window.
2020-09-01 19:55:58 -07:00
Ryan Rehman
60eef68f59
refactor: Extract `set_up_typeahead_on_pills` to a new file.
...
We move this function from `user_pill.js` to `pill_typeahead.js`.
The function has also been renamed to `set_up`.
The move was made because there are plans to update the pills
typeahead (i.e. to include user-groups/streams in the results).
Thus this function should not belong in `user_pill.js`.
2020-08-04 15:58:12 -07:00
Anders Kaseorg
6ec808b8df
js: Add "use strict" directive to CommonJS files.
...
ES and TypeScript modules are strict by default and don’t need this
directive. ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
Anders Kaseorg
d2520cd7e0
js: Replace underscore with lodash and remove it from globals.
...
Tweaked by tabbott to bump PROVISION_VERSION.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 16:12:06 -07:00
Ryan Rehman
6a245d6d93
minor: Refactor `set_up_typeahead_on_pills` function interface.
...
This is a prep commit which passes the `update_func` and `source`
data through an object. This will be helpful as there are plans
to pass furthur information to the function (i.e. whether we should
allow creating pills from streams and/or user-groups).
2020-07-22 17:00:34 -07:00
Anders Kaseorg
96dcc0ce6e
js: Use ES6 object literal shorthand syntax.
...
Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:42:22 -07:00
Anders Kaseorg
a9ca5f603b
js: Replace deprecated jQuery event trigger shorthand.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg
97feea42a1
js: Replace deprecated jQuery.fn.hover.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:01:26 -07:00
Anders Kaseorg
b65d2e063d
js: Reformat with Prettier.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
a20c12366f
js: Use inside variant of IIFE wrappers.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg
f3726db89a
js: Normalize strings to double quotes.
...
Prettier would do this anyway, but it’s separated out for a more
reviewable diff. Generated by ESLint.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Anders Kaseorg
e014ea966a
eslint: Enable comma-dangle for functions.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg
a79322bc94
eslint: Enable prefer-arrow-callback.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
Anders Kaseorg
b0253c5a2e
eslint: Enable arrow-parens.
...
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:53:39 -07:00
Anders Kaseorg
72dddb7af6
zjsunit: Use assert in strict mode.
...
This makes assert.equal and assert.deepEqual compare using === rather
than ==, to catch more bugs.
https://nodejs.org/api/assert.html#assert_strict_mode
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-12 08:16:26 -05:00
Anders Kaseorg
70ff164f89
js: Convert _.any(a, …), _.some(a, …) to a.some(…).
...
And convert the corresponding function expressions to arrow style
while we’re here.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-10 14:08:12 -08:00
Anders Kaseorg
02511bff1c
js: Automatically convert _.each to for…of.
...
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-07 14:09:47 -08:00
Steve Howell
b8f01f9cda
people: Rename method to get_by_user_id().
...
This name is consistent with:
get_by_email()
get_by_name()
2020-02-05 12:04:56 -08:00
Anders Kaseorg
de3146c137
js: Replace [...x] with Array.from(x).
...
Babel strict generates more code for [...x] than you’d like, while
Babel loose mode assumes x is an array.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-05 11:52:52 -08:00
Steve Howell
ef892271dc
int_dict: Fix type errors for user_groups.
...
This fixes some harmless type errors from the
following commit:
6ec5a1f306
The IntDict code automatically converts strings to
integers, so this was not a user-facing problem, but
we want to have our callers do the conversions
explicitly.
2020-01-27 13:14:40 -05:00
Anders Kaseorg
4341b7b252
user_groups: Convert members from Dict to Set.
...
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-01-16 13:23:47 -08:00
Anders Kaseorg
f9f104a4f8
js: Automatically convert var to let and const in more files.
...
This commit was automatically generated by `tools/lint --only=eslint
--fix`, after an `.eslintrc.json` change.
A half dozen files were removed from the changes by tabbott pending
further work to ensure we avoid breaking valuable PRs with merge
conflicts.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-11-20 14:10:47 -08:00
Matheus Melo
c96762b7a9
settings: Add setting for who can edit user groups.
...
Fixes #12380 .
2019-11-03 16:45:13 -08:00
Anders Kaseorg
d17b577d0c
js: Purge useless IIFEs.
...
With webpack, variables declared in each file are already file-local
(Global variables need to be explicitly exported), so these IIFEs are
no longer needed.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2019-10-25 13:51:21 -07:00
Anders Kaseorg
db0b33842c
templates: Replace templates.render with require calls.
...
This removes an unnecessary layer of indirection and allows webpack to
catch filename mistakes.
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2019-07-12 21:11:14 -07:00
Tim Abbott
838dd6d273
lint: Add eslint enforcement for comma-spacing.
...
We've been enforcing this manually for a long time, and hadn't
realized it was missing from our eslint configuration.
2018-12-07 12:22:24 -08:00
Steve Howell
3545bc1893
settings: Confirm before deleting user groups.
...
Fixes #10498 .
2018-10-12 10:38:56 -07:00
Steve Howell
19ca7145fc
settings: Extract delete_user_group().
...
This preps us to make delete_user_group() be
a callback in the next commit.
2018-10-12 10:38:54 -07:00
Yashashvi Dave
9812b81a1e
user pills: Rename class `notmem` to `not-editable` for generalization.
2018-08-21 11:50:01 -07:00
Cynthia Lin
300c4c496f
user groups: Display error on user group name edit failure.
...
Fixes #10234 .
2018-08-13 16:13:49 -07:00
Cynthia Lin
736388b4df
user groups: Improve styling of user groups in admin view.
2018-08-13 16:13:49 -07:00
Armaan Ahluwalia
6d255efe4c
app: Prepare JS files for consumption by webpack.
...
This commit prepares the frontend code to be consumed by webpack.
It is a hack: In theory, modules should be declaring and importing the
modules they depend on and the globals they expose directly.
However, that requires significant per-module work, which we don't
really want to block moving our toolchain to webpack on.
So we expose the modules by setting window.varName = varName; as
needed in the js files.
2018-07-05 10:53:36 +02:00
Shubham Dhama
8e032376f9
guest: Restrict guest access to user group creation and updation.
2018-06-19 11:04:14 -07:00
Shubham Dhama
05323e776e
user groups: Refactor settings_user_groups.can_edit.
2018-06-19 11:04:14 -07:00
Shubham Dhama
80a2d5bc59
eslint: Enable `conditionalAssign` config of no-trailing-spaces rule.
2018-06-11 07:51:24 -04:00
Shubham Dhama
dcb6254a4e
eslint: Enable `no-extra-parens` rule.
...
Following sub-configuration is disabled:
"nestedBinaryExpressions": false,
2018-06-11 07:51:24 -04:00
Cynthia Lin
818611ac4e
user groups: Sanitize pill_container selector to avoid escaped strings.
...
Fixes #9325 .
2018-05-25 12:02:34 -07:00
Yashashvi Dave
958040b1fc
user_pills: Extract generic functions for typeahead and pill creation.
...
This refactoring make it easier to use our user pill typeahead logic
in other parts of the app.
Two commits by Yashasvhi squashed together by Tim.
2018-05-23 12:07:16 -07:00
Tim Abbott
7ab8a8e820
js: Fix a bunch of indentation issues found by eslint.
...
This is preparation for enabling an eslint indentation configuration.
90% of these changes are just fixes for indentation errors that have
snuck into the codebase over the years; the others are more
significant reformatting to make eslint happy (that are not otherwise
actually improvements).
The one area that we do not attempt to work on here is the
"switch/case" indentation.
2018-05-06 16:25:02 -07:00
Steve Howell
aac76c14bd
settings: Avoid duplicate form handlers.
...
For forms that are built early in setting up the settings panel,
we don't want to attach multiple submit handlers every time we
go into the gear menu, so we use "off" to clear any old handlers.
We also attach handlers directly to the form, instead of
using delegation up to the container div.
2018-03-25 08:28:04 -07:00
Tarun Kumar
d403b7a2d5
user-groups: Prevent user not in user group from editing/deleting it.
...
Admin and user group members are allowed to edit/delete group.
Add node-tests to maintain 100% coverage for settings_user_groups.js
Fixes #8315 .
2018-03-23 14:44:47 -07:00
Tarun Kumar
59b1f59605
user-groups: Add function wrappers to reduce variable scope.
...
Extract set_up_typeahead function.
Extract pill_remove function.
2018-03-22 16:48:46 -07:00
Shubham Padia
4fb1704e6e
settings: Add save instructions below pill container on changes.
...
Fixes #8088 .
2018-03-15 17:29:12 -07:00
Shubham Padia
dd5ce49ce0
settings: Add button to cancel user group auto save on blur.
...
Clicking the cancel button removes all the changes and the user
group returns back to the original state. Saved button is showed
once the changes are saved on blur.
2018-03-15 17:29:12 -07:00