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

#23603 : Allow users to write code when creating a file - PR2 #24267

Merged
merged 15 commits into from
Mar 10, 2023

Conversation

jcastro-dotcms
Copy link
Contributor

Proposed Changes

  • Allow users to write code when creating a file. A new method was added to the Temp File API and the Temp File Endpoint to allow back-end users to "upsert" a temporary file.
  • The Text Area field is displayed when a new File Asset is created. This way, Users can either upload a binary file, or start typing its contents in the Text Area field.
  • The initial mechanism used to create the content of the File Asset is the same one used when we're editing an existing text File Asset.

@jcastro-dotcms jcastro-dotcms linked an issue Mar 3, 2023 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Unit Tests Report

1 422 tests  ±0   1 412 ✔️ ±0   3m 51s ⏱️ -3s
   140 suites ±0        10 💤 ±0 
   140 files   ±0          0 ±0 

Results for commit 94b7d3a. ± Comparison against base commit 4d158c9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Postman Tests Report

     65 files  ±0  1 407 suites  +3   3h 40m 24s ⏱️ -38s
   629 tests +5     625 ✔️ +4  0 💤 ±0  4 +1 
2 341 runs  +5  2 335 ✔️ +4  0 💤 ±0  6 +1 

For more details on these failures, see this check.

Results for commit 94b7d3a. ± Comparison against base commit 4d158c9.

This pull request removes 1 and adds 6 tests. Note that renamed tests count towards both.
TempApi ‑ File name check
TempApi ‑ Checking file names and operation status code
TempApi ‑ New Temporary File ID must NOT match the previous one
TempApi ‑ Non-Existing Test Temporary File creation HTTP Status must be successful
TempApi ‑ Temporary File ID must be the same
TempApi ‑ Test Temporary File creation HTTP Status must be successful
TempApi ‑ Test Temporary File update HTTP Status must be successful

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Integration Tests [postgres] Report

   409 files  ±0     409 suites  ±0   1h 27m 9s ⏱️ - 10m 6s
3 905 tests ±0  3 879 ✔️ ±0  23 💤 ±0  3 ±0 
3 926 runs  ±0  3 900 ✔️ ±0  23 💤 ±0  3 ±0 

For more details on these failures, see this check.

Results for commit 94b7d3a. ± Comparison against base commit 4d158c9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Integration Tests [mssql] Report

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit 94b7d3a. ± Comparison against base commit 4d158c9.

♻️ This comment has been updated with latest results.

* @param tempFileId The ID of the Temporary File.
*
* @return The {@link DotTempFile} matching the specified ID.
*/
private Optional<DotTempFile> getTempFile(final String tempFileId) {

if (tempFileId == null || !tempFileId.startsWith(TEMP_RESOURCE_PREFIX)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

tempFileId = jsonData.tempFiles[0].id;
const elements = document.getElementsByName("<%= field.getFieldContentlet() %>");
for (let i = 0; i < elements.length; i++) {
if (elements[i].tagName.toLowerCase() == "input") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (elements[i].tagName.toLowerCase() == "input") {
if (elements[i].tagName.toLowerCase() === "input") {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

const jsonData = JSON.parse(xhr.response);
tempFileId = jsonData.tempFiles[0].id;
const elements = document.getElementsByName("<%= field.getFieldContentlet() %>");
for (let i = 0; i < elements.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for (let i = 0; i < elements.length; i++) {
for (const element of elements) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

FileAssetAjax.saveFileText(contentletInode.value, text, '<%=field.getVelocityVarName()%>', {
async: false,
callback: function (data) {
console.log("savedText");
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these logs?

Suggested change
console.log("savedText");
console.warn("savedText");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing code.


xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need these logs?

Suggested change
console.log(this.responseText);
console.warn(this.responseText);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing code.

@fmontes fmontes merged commit b6f0095 into master Mar 10, 2023
@fmontes fmontes deleted the issue-23603-write-code-when-creating-file-pr2 branch March 10, 2023 17:45
@dotcms-sonarqube
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 0.0% 0.0% Coverage on New Code (is less than 80%)

See analysis details on SonarQube

dsilvam added a commit that referenced this pull request Apr 6, 2023
dsilvam added a commit that referenced this pull request Apr 6, 2023
wezell added a commit that referenced this pull request Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EC: Allow users to write code when create a file
5 participants